Word7 VBA- need a desk top icon to open directly to userform
-
- NewLounger
- Posts: 21
- Joined: 20 May 2014, 18:12
Word7 VBA- need a desk top icon to open directly to userform
How do I have a desk top icon open the user form and the user form needs to be a full screen.
-
- Administrator
- Posts: 78642
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Word7 VBA- need a desk top icon to open directly to user
To maximize the userform, you need to put code in the userform's code module:
You need to have a macro in the document that displays the userform. In the document that I attached in your first thread, this macro is named Test.
If you always want to display the userform when the document opens, call Test from the Document_Open event procedure in the ThisDocument module. Otherwise, you have to call the macro from the shortcut. I found, however, that you shouldn't call it directly because of timing problems, so I added another macro that waits 1 second before running Test:
The target of the shortcut looks like this:
"C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE" "C:\Docs\ScreenshotDemo.docm" /mStartIt
You must, of course, specify the correct path to WINWORD.EXE, and the correct path of the document.
Note that there is no space between /m and the name of the macro.
I have attached the modified document.
Code: Select all
Private Sub UserForm_Initialize()
Dim ws As WdWindowState
With Application
' Store current window state in variable
ws = .WindowState
' Maximize application
.WindowState = wdWindowStateMaximize
' Resize userform to application size
Me.Width = .Width
Me.Height = .Height
' Restore the application's original window state
.WindowState = ws
End With
End Sub
Code: Select all
Sub Test()
frmDemo.Show
End Sub
Code: Select all
Sub StartIt()
Application.OnTime DateAdd("s", 1, Now), "Test"
End Sub
"C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE" "C:\Docs\ScreenshotDemo.docm" /mStartIt
You must, of course, specify the correct path to WINWORD.EXE, and the correct path of the document.
Note that there is no space between /m and the name of the macro.
I have attached the modified document.
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans
Hans
-
- NewLounger
- Posts: 21
- Joined: 20 May 2014, 18:12
Re: Word7 VBA- need a desk top icon to open directly to user
Thank you so much for your help! But do to my lack of VBA knowledge I can't decipher your short cut instructions. Right now in order to pull up the user form, I have to click the ribbon in Word then choose recent document and when I click on the userform it does pull up the userform with a full size screen(which it great). I know in Excel VBA the below code works for a shortcut but of course it doesn't work in Word VBA. It gets hung up on Activeworkbook.
Code: Select all
Sub CreateShortCut()
Dim oWSH As Object
Dim oShortcut As Object
Dim sPathDeskTop As String
Set oWSH = CreateObject ("WScript.Shell")
sPathDeskTop = oWSH.SpecialFolders("Desktop")
Set oShortcut = oWSH.CreateShortCut(sPathDeskTop & "\" _
ActiveWOrkbook.Name & ".lnk")
With oShortcut
.TargetPath = ActiveWorkbook.Fullname
.Save
End With
Set oWSH = Nothing
End Sub
[code]
-
- Administrator
- Posts: 78642
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Word7 VBA- need a desk top icon to open directly to user
To create a code block, use [code]...[/code] instead of [code]...[code]
The equivalent of your macro for Word is
(ActiveDocument instead of ActiveWorkbook)
The equivalent of your macro for Word is
Code: Select all
Sub CreateShortCut()
Dim oWSH As Object
Dim oShortcut As Object
Dim sPathDeskTop As String
Set oWSH = CreateObject("WScript.Shell")
sPathDeskTop = oWSH.SpecialFolders("Desktop")
Set oShortcut = oWSH.CreateShortCut(sPathDeskTop & "\" & _
ActiveDocment.Name & ".lnk")
With oShortcut
.TargetPath = ActiveDocument.FullName
.Save
End With
Set oWSH = Nothing
End Sub
Best wishes,
Hans
Hans
-
- NewLounger
- Posts: 21
- Joined: 20 May 2014, 18:12
Re: Word7 VBA- need a desk top icon to open directly to user
Your awesome, it's working ☺