Results 1 to 4 of 4

Thread: Changing Excell Height and Width

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Posts
    29

    Changing Excell Height and Width

    Hiiiii,
    I am opening an Excell file using Excell object Library.

    Dim xlTmp As Excel.Application
    Dim sparth As String
    Dim formwidth As Double

    Set xlTmp = New Excel.Application
    xlTmp.Workbooks.Open File1.Path & "\" & sparth,
    xlTmp.Left = 20000
    Set xlTmp.Width = 774
    xlTmp.Height = 561 'Screen.Height - 5000
    xlTmp.Width = 553
    xlTmp.Visible = True

    But when I am trying to set the Height and the Width of the Excel file it give the following error...

    Runtime Error
    "Method Height of object Application failed"

    I need to change the Height and width of the opend excell file at run time......

    Can anyone help me on this....


    Thanks
    Sam


  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    At a guess, I cant test this theory out at the moment; however, I think
    you may need to include a worksheet object, and Set that to the existing xlTmp.

    What you are trying to do is adjust the application width/height, and you need to be adjusting the Worksheet width/height.




    Bruce.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Posts
    29
    Hiii,
    I tired it But there's no property to set the worksheet Height and width......


    Sam

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    In order to change any height/width props of the main window, it
    needs to be in a windowstate of Normal, not maximized or
    minimized. This will work.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.  
    5.     Dim xlTmp As Excel.Application
    6.     Dim sparth As String
    7.     Dim formwidth As Double
    8.    
    9.     Set xlTmp = New Excel.Application
    10.     xlTmp.Workbooks.Open "D:\My Documents\Book1.xls"
    11.     [b][color=red]xlTmp.WindowState = xlNormal[/color][/b]
    12.     xlTmp.Left = 20000
    13.     xlTmp.Width = 774
    14.     xlTmp.Height = 561 'Screen.Height - 5000
    15.     xlTmp.Width = 553
    16.     xlTmp.Visible = True
    17.  
    18. End Sub
    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