Stuck! Need Help!

D

Dodger Jim

I have a shell document that I have written a macro for so when the document
is opened, the macro runs automatically upon opening. The last part of the
macro opens the SaveAs dialog box for the user to save the document to a new
name. After the user puts makes their directory choices and a new name, they
click save and the document does not save to the new name. The macro simply
stops and the shell document remains on the screen. To complicate this even
further, if I run this macro from the VBA IDE, it runs and saves perfectly!
Can someone please give me some help here? I feel like I've hit a brick
wall! Thank you!
 
H

Helmut Weber

Hi Jim,

was a construction using "ontime" too complicated?
Did you try?

If you run a macro from the VBA IDE and it works
and again via automation and it doesn't, there
seems to be a timing issue.

I had a problem placing toolbars in autoopen.
No way! The toolbars didn't exist until autoopen was finished,
though I did see them.

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
D

Dodger Jim

I don't understand 'on-time.' I read what you wrote before and didn't
understand that either. I guess I need more detailed specific help with how
to do what you're suggesting. Thanks!
 
A

axeman

Try having your AutoOpen macro pointing to your actual macro that does all
the work. So you would have:

Public Sub AutoOpen()
Application.Run MacroName:="YourMacro"
End Sub

Public Sub YourMacro()

Enter your code here

End Sub

I think that's what he meant. That he had problems running a toolbar macro
that ran as an AutoOpen macro. Give it a twirl and let us know...

Axe
 
D

Dodger Jim

I found the OnTime Method and learned how to use it - I think. Is my code
correct:

Application.OnTime When:=Now + "timeValue("00:00:10"), _
Name:="Memorandum.frmNewName.UserForm_Initialize"

Where I have the word 'Application' above, do I need something else?
Where do I put this code once I get it right?
Thanks!
 
D

Dodger Jim

Thank you! I'll try it!

axeman said:
Try having your AutoOpen macro pointing to your actual macro that does all
the work. So you would have:

Public Sub AutoOpen()
Application.Run MacroName:="YourMacro"
End Sub

Public Sub YourMacro()

Enter your code here

End Sub

I think that's what he meant. That he had problems running a toolbar macro
that ran as an AutoOpen macro. Give it a twirl and let us know...

Axe
 
D

Dodger Jim

I still don't have something right. I have not been using an AutoOpen()
macro. I have been using the following code in the Document Code Window of
the Microsoft Word Objects, ThisDocument:

Private Sub Document_Open()
Load frmNewForm
frmNewForm.Show
End Sub

Then in the frmNewForm I start my code in the UserForm_Initialize()
subroutine.

Where do I put the AutoOpen()?

In your example, where you have 'YourMacro()', is that where I put
'UserForm_Initialize()'?

Sorry to be such a pain, but I feel like I'm floundering in the dark! Thanks!
 
H

Helmut Weber

Hi Jim,

Can't test all, that doesn't work.
This one works for me:

Sub Autoopen()
' some code possible here
Application.OnTime _
When:=Now + TimeValue("00:00:05"), _
Name:="MacroAfterAutoopen"
' and nothing here to make sure,
' that autoopen has been completed before
' MacroAfterAutoopen starts
End Sub
Sub MacroAfterAutoopen()
MsgBox "MacroAfterAutoopen"
' show your userform etc...
' or start other seemably time critical code...
End Sub

This solved some problems for me, though
I can't guarantee, it will solve yours.

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
D

Dodger Jim

I tried your suggestion and it still didn't solve my problem. Thanks for
sticking with me!
 

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