Consulting

Results 1 to 3 of 3

Thread: Maximum workbook and set to page layout view

  1. #1
    VBAX Regular
    Joined
    Mar 2018
    Location
    Leesburg
    Posts
    68
    Location

    Maximum workbook and set to page layout view

    Hello, I have a Word VBA which creates an Excel spreadsheet.
    However, I cannot for the life of me figure out how to make the workbook display maximized and also change to page layout view.
    Instead, it shows up as a small window, and in Normal view.
    I have tried everything I can think of, and have Googled, and all the code I find indicates that what I have should work, but it doesn't.

    Can anyone please help me? What I thought should be simple has become quite frustrating.

    Private Sub ExcelMax()
            Dim ExcelApp As Object, ExcelWB As Object, ExcelWS As Object
            Dim StrOut As String
            Set ExcelApp = CreateObject("Excel.Application")
            ExcelApp.Visible = False
            Set ExcelWB = ExcelApp.Workbooks.Add
            ExcelApp.Visible = True
            Set ExcelWS = ExcelWB.Sheets(1)
            ExcelWB.Activate
            Application.WindowState = xlMaximized
            ActiveWindow.View = xlPageLayoutView
    End Sub
    Sincerely,
    Doug

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Try this Word macro




    Option Explicit
    
    Sub ExcelMax()
        Dim ExcelApp As Object, ExcelWB As Object, ExcelWS As Object
        Dim StrOut As String, strCaption As String
        
        Set ExcelApp = CreateObject("Excel.Application")
        ExcelApp.Visible = False
        Set ExcelWB = ExcelApp.Workbooks.Add
        ExcelApp.Visible = True
        
        strCaption = ExcelApp.Caption
        
        Set ExcelWS = ExcelWB.Sheets(1)
        
        AppActivate strCaption
        
        ExcelApp.WindowState = -4137    'xlMaximized
        ExcelApp.Windows(1).View = 3    'xlPageLayoutView
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Regular
    Joined
    Mar 2018
    Location
    Leesburg
    Posts
    68
    Location
    Paul, that worked perfectly!
    Thank you very much!
    Doug

Tags for this Thread

Posting Permissions

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