|
-
Apr 14th, 2004, 09:50 AM
#1
Thread Starter
Hyperactive Member
unsure what to Set object to
Hello,
I'm having a problem with this code when viewed online. Here's the code:
VB Code:
Private Sub UserForm_Initialize()
Dim OldState As Integer
OldState = Application.WindowState
Application.WindowState = xlMaximized
Me.Top = Application.Top
Me.Left = Application.Left
Me.Height = Application.Height
Me.Width = Application.Width
Application.WindowState = OldState
End Sub
Evidently I must explicitly define "Application". So when I add:
Dim xlApp as Excel.Application
I'm unsure of what to set it to:
Set xlApp = ????????
I tried adding "Excel.Application" to each line:
OldState = Excel.Application.WindowState
Excel.Application.WindowState = xlMaximized
etc....
but I'm still getting error 1004, object not SET. What do I set the object to? This is straight Excel/VBA.
Thank you,
CJ
-
Apr 14th, 2004, 12:52 PM
#2
What about...
VB Code:
Private Sub UserForm_Initialize()
Dim xlApp as Excel.Application
Dim OldState As Integer
Set xlApp = New Excel.Application
xlApp.WindowState = xlMaximized
Me.Top = xlApp.Top
Me.Left = xlApp.Left
Me.Height = xlApp.Height
Me.Width = xlApp.Width
xlApp.WindowState = OldState
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Apr 14th, 2004, 03:01 PM
#3
Thread Starter
Hyperactive Member
Cool Robdog,
You're amazing! This worked - using New solved it. I only added:
xlApp.Quit
Set xlApp = Nothing
Thanks,
CJ
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|