[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 594
  • Last Modified:

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_table '** THE ERROR HIGHLIGHTS THIS LINE **
End Sub

Thanks

Ross
0
rossh1977
Asked:
rossh1977
  • 7
  • 4
1 Solution
 
gilbarCommented:
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?
0
 
gilbarCommented:
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



0
 
rossh1977Author Commented:
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
0
Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

 
gilbarCommented:
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
0
 
rossh1977Author Commented:
Hi gilbar,  Thanks for gettign back to me, just tired that but it didn't work?  Worked in 2003 not in 2002??

Thanks

Ross
0
 
gilbarCommented:
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
0
 
rossh1977Author Commented:
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.AddHorizontalLine FileName:= _
    "C:\Program Files\Microsoft Office\MEDIA\OFFICE11\Lines\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
0
 
gilbarCommented:
That line should work, assuming that "C:\Program Files\Microsoft Office\MEDIA\OFFICE11\Lines\BD10219_.gif"
exists on that machine. I'm guessing that since that machine has word 2002 (Office10), you'd be MUCH better off using :
"C:\Program Files\Microsoft Office\MEDIA\OFFICE10\Lines\BD10219_.gif"

So now the question becomes: how do you get it to work on BOTH word2002 and word2003. If you care, you could do something like :

If Len(Dir("C:\Program Files\Microsoft Office\MEDIA\OFFICE10\Lines\BD10219_.gif")) > 0 Then
       Selection.InlineShapes.AddHorizontalLine FileName:= _
    "C:\Program Files\Microsoft Office\MEDIA\OFFICE10\Lines\BD10219_.gif"
End If

If Len(Dir("C:\Program Files\Microsoft Office\MEDIA\OFFICE11\Lines\BD10219_.gif")) > 0 Then
       Selection.InlineShapes.AddHorizontalLine FileName:= _
    "C:\Program Files\Microsoft Office\MEDIA\OFFICE11\Lines\BD10219_.gif"
End If



0
 
rossh1977Author Commented:
Nice one Gilbar i'll give it a go.  Thanks for all your help!
0
 
gilbarCommented:
I suppose you should next those ifs just in case someone has both words, wouldn't want two lines, would we :)
0
 
gilbarCommented:
Glad to help rossh. Have a happy memorial day weekend !
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now