Results 1 to 6 of 6

Thread: Preview

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Location
    Cleveland,Oh
    Posts
    95

    Preview

    Hi All:
    I need help on how to code in vb to preview excel report. I tried the following line of code, but I get an error.

    EXCELOBJ.ActiveWorkbook.PrintPreview

    Thanks
    Zus

  2. #2
    Addicted Member
    Join Date
    Aug 2002
    Location
    Luton, UK
    Posts
    178
    Your code as shown is correct. Try
    EXCELOBJ.ActiveSheet.PrintPreview

    If this doesn't work we will need to see more of your code.
    If the sheet is blank it will not work.
    Regards
    BrianB
    -------------------------------

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Location
    Cleveland,Oh
    Posts
    95

    Print Preview

    Hi BrianB:

    The print Preview still does not work. Please find below my codes.

    Dim EXCELOBJ As Excel.Application
    Dim EXCELBOOK As Excel.Workbook ' Workbook object
    Dim EXCELSHEET As Excel.Worksheet 'Worksheet object

    SaveFile = ""
    FileExtension = "*.xls"
    SourcePath = "S:\"
    FileName = Dir(SourcePath & FileExtension, vbNormal)
    SaveFile = App.Path & "\Rpts\" & File

    'Create Excel Object
    Set EXCELOBJ = CreateObject("Excel.Application")
    EXCELOBJ.Visible = False
    EXCELOBJ.Workbooks.Open FileName:=App.Path & "\Rpts\" &

    Set EXCELBOOK = EXCELOBJ.ActiveWorkbook
    Set EXCELSHEET = EXCELBOOK.ActiveSheet
    Set EXCELSHEET = EXCELOBJ.ActiveWorkbook.Sheets(1)
    Set EXCELSHEET = EXCELBOOK.ActiveSheet

    'I have a loop that populate and create my excel file here

    'Print preview
    EXCELOBJ.ActiveSheet.PrintPreview (when this line is executed, I get an error. The error is "This action cannot be completed because other application is busy.")

    What do I need to do?

    Thanks



    Zus

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    This works for me. You need to set the visible property
    to true before you do a printpreview.

    VB Code:
    1. EXCELOBJ.Visible = True
    2. EXCELOBJ.ActiveSheet.PrintPreview
    HTH
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Location
    Cleveland,Oh
    Posts
    95

    Resolved: Print Preview

    Thanks for your help!!!
    Zus

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    No prob.

    Don't forget to edit you original post's subject with [Resolved]
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width