How do I show a userform only if a docm has a certain name?

T

ThinkPink

I am trying to place a .docm document on our intranet for employees to use a
specific format for official letters. This document has a userform that
should show when it is opened opened for the first time but not after it has
been saved with a new name. The problem comes in when the first new document
opens as "Notice[1].docm" then the next new document opens as
"Notice[2].docm", and so on.

Is there code that can recognize "Notice" but follow it with a wildcard so
the userform will show.

My current code is:
Sub autoopen()
With ThisDocument
If ActiveDocument.Name = "Notice.docm" Then
NoticeForm.Show
Else
NoticeForm.Hide
End If
End With
End Sub
 
G

Greg Maxey

I think what you need to do is create a template to use for creating your
new Notice documents.

Then in the template have a procedure named AutoNew

Sub AutoNew
Dim oFrm as NoticeForm
Set oFrm = New NoticeForm
oFrm.Show
Unload oFrm
Set oFrm = Nothing
End Sub


I am trying to place a .docm document on our intranet for employees
to use a specific format for official letters. This document has a
userform that should show when it is opened opened for the first time
but not after it has been saved with a new name. The problem comes
in when the first new document opens as "Notice[1].docm" then the
next new document opens as "Notice[2].docm", and so on.

Is there code that can recognize "Notice" but follow it with a
wildcard so the userform will show.

My current code is:
Sub autoopen()
With ThisDocument
If ActiveDocument.Name = "Notice.docm" Then
NoticeForm.Show
Else
NoticeForm.Hide
End If
End With
End Sub
 
T

ThinkPink

Now when I hit "Submit" I get an error message saying "Must close or hide
topmost modal form first."
Debug takes me to NoticeForm.hide
I tried replacing with oFrm.hide but I get the same message.




Greg Maxey said:
I think what you need to do is create a template to use for creating your
new Notice documents.

Then in the template have a procedure named AutoNew

Sub AutoNew
Dim oFrm as NoticeForm
Set oFrm = New NoticeForm
oFrm.Show
Unload oFrm
Set oFrm = Nothing
End Sub


I am trying to place a .docm document on our intranet for employees
to use a specific format for official letters. This document has a
userform that should show when it is opened opened for the first time
but not after it has been saved with a new name. The problem comes
in when the first new document opens as "Notice[1].docm" then the
next new document opens as "Notice[2].docm", and so on.

Is there code that can recognize "Notice" but follow it with a
wildcard so the userform will show.

My current code is:
Sub autoopen()
With ThisDocument
If ActiveDocument.Name = "Notice.docm" Then
NoticeForm.Show
Else
NoticeForm.Hide
End If
End With
End Sub
 
D

Doug Robbins - Word MVP

Put Me.Hide in the code that is run by your Submit button.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
ThinkPink said:
Now when I hit "Submit" I get an error message saying "Must close or hide
topmost modal form first."
Debug takes me to NoticeForm.hide
I tried replacing with oFrm.hide but I get the same message.




Greg Maxey said:
I think what you need to do is create a template to use for creating your
new Notice documents.

Then in the template have a procedure named AutoNew

Sub AutoNew
Dim oFrm as NoticeForm
Set oFrm = New NoticeForm
oFrm.Show
Unload oFrm
Set oFrm = Nothing
End Sub


I am trying to place a .docm document on our intranet for employees
to use a specific format for official letters. This document has a
userform that should show when it is opened opened for the first time
but not after it has been saved with a new name. The problem comes
in when the first new document opens as "Notice[1].docm" then the
next new document opens as "Notice[2].docm", and so on.

Is there code that can recognize "Notice" but follow it with a
wildcard so the userform will show.

My current code is:
Sub autoopen()
With ThisDocument
If ActiveDocument.Name = "Notice.docm" Then
NoticeForm.Show
Else
NoticeForm.Hide
End If
End With
End Sub
 
T

ThinkPink

Perfect! Thanks to both you and Greg!!!


Doug Robbins - Word MVP said:
Put Me.Hide in the code that is run by your Submit button.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
ThinkPink said:
Now when I hit "Submit" I get an error message saying "Must close or hide
topmost modal form first."
Debug takes me to NoticeForm.hide
I tried replacing with oFrm.hide but I get the same message.




Greg Maxey said:
I think what you need to do is create a template to use for creating your
new Notice documents.

Then in the template have a procedure named AutoNew

Sub AutoNew
Dim oFrm as NoticeForm
Set oFrm = New NoticeForm
oFrm.Show
Unload oFrm
Set oFrm = Nothing
End Sub



ThinkPink wrote:
I am trying to place a .docm document on our intranet for employees
to use a specific format for official letters. This document has a
userform that should show when it is opened opened for the first time
but not after it has been saved with a new name. The problem comes
in when the first new document opens as "Notice[1].docm" then the
next new document opens as "Notice[2].docm", and so on.

Is there code that can recognize "Notice" but follow it with a
wildcard so the userform will show.

My current code is:
Sub autoopen()
With ThisDocument
If ActiveDocument.Name = "Notice.docm" Then
NoticeForm.Show
Else
NoticeForm.Hide
End If
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top