rossh1977
asked on
Correct syntax for calling a sub routine in MS Office XP 2000 - 2003
Hi I've written a macro in MS office 2003 and i've just tested it in MS office 2002 and it works but i'm getting a Run-Time Error '5152', This is not a valid file name when the macro is run. In the VBA the code below is highlighted. Is there a way of calling a sub routine in 200 onwards which is now different to 2003 or could something else be wrong?
Private Sub cmd_ok_Click()
frm_new_section.Hide
Call ActiveDocument.create_tabl e '** THE ERROR HIGHLIGHTS THIS LINE **
End Sub
Thanks
Ross
Private Sub cmd_ok_Click()
frm_new_section.Hide
Call ActiveDocument.create_tabl
End Sub
Thanks
Ross
The call part works in Word 2002, it's the .create_table part it doesn't understand. Is this a subroutine you wrote? or is it in word2003?
in Word2002, if you have a subroutine named 'q' in a module named 'ModuleName', then you could call it like this:
Call ModuleName.q
or like this:
ModuleName.q
or (if you are already in that Module, or don't have any other subroutines named 'q', like this:
q
Call ModuleName.q
or like this:
ModuleName.q
or (if you are already in that Module, or don't have any other subroutines named 'q', like this:
q
ASKER
Hi the sub routine is in ThisDocument. The .create_table is my sub routine that i'm calling? Should i move the routine into a module. How would this affect my ability to run the macro from the toolbar?
Thanks
Ross
Thanks
Ross
Oh, In your code you're calling from Activedocument, not ThisDocument. That might work in word2003, but in word 2002 try:
Call thisDocument.create)Table
Call thisDocument.create)Table
ASKER
Hi gilbar, Thanks for gettign back to me, just tired that but it didn't work? Worked in 2003 not in 2002??
Thanks
Ross
Thanks
Ross
hmmm,
Call ThisDocument.create_Table works for me when i put a macro create_Table into my ThisDocument section. Are you still getting the same error as when you were calling from ActiveDocument? When I try to call a macro that doesn't exist
like Call ThisDocument.create_Tabl I get a compile error: methof or data member not found. Your error is a 5152 instead of a compile error?
What happens when you go into Visual Basic editor and step into the create.Table macro itself? does it work ? I wonder if the problem is in that macro, not the calling macro
Call ThisDocument.create_Table works for me when i put a macro create_Table into my ThisDocument section. Are you still getting the same error as when you were calling from ActiveDocument? When I try to call a macro that doesn't exist
like Call ThisDocument.create_Tabl I get a compile error: methof or data member not found. Your error is a 5152 instead of a compile error?
What happens when you go into Visual Basic editor and step into the create.Table macro itself? does it work ? I wonder if the problem is in that macro, not the calling macro
ASKER
Ahhhhh, at the last minute i added a horizontal line to the page and thought hmm better watch incase this isn't available on all workstations!!!!
Selection.InlineShapes.Add Horizontal Line FileName:= _
"C:\Program Files\Microsoft Office\MEDIA\OFFICE11\Line s\BD10219_ .gif"
I've ommited this line and it works fine. Is there anyway i can incorporate a horizontal line like this one for 2002 and check the versions, if no easy way then i can leave it out!
Thanks very much gilbar!
Ross
Selection.InlineShapes.Add
"C:\Program Files\Microsoft Office\MEDIA\OFFICE11\Line
I've ommited this line and it works fine. Is there anyway i can incorporate a horizontal line like this one for 2002 and check the versions, if no easy way then i can leave it out!
Thanks very much gilbar!
Ross
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Nice one Gilbar i'll give it a go. Thanks for all your help!
I suppose you should next those ifs just in case someone has both words, wouldn't want two lines, would we :)
Glad to help rossh. Have a happy memorial day weekend !