Results 1 to 18 of 18

Thread: App.Path in Word ?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2004
    Location
    SouthWest
    Posts
    120

    Unhappy App.Path in Word ?

    Hello all-

    Im running a macro in Word. It runs when you open the document and its a mail merge doc. I need it to find the db in the folder where the form is located...(App.Path in VB) I know its Application.Path in Word but I paced that in and im getting syntax error among others my code is below... can anyone help? Thanks!

    VB Code:
    1. Private Sub Document_Open()
    2. CommandBars("Mail Merge").Visible = True
    3.     ActiveDocument.MailMerge.OpenDataSource Name:= _
    4.         [COLOR=Red]" & Application.Path & "\Tracking Data.mdb", ConfirmConversions[/COLOR]:= _
    5.         False, ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
    6.         PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
    7.         WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _
    8.         Connection:= _
    9.         "Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data [COLOR=Red]Source=" & Application.Path & ";Mode=Read;Extended Properties="""";Jet [/COLOR] OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engin" _
    10.         , SQLStatement:="SELECT * FROM `FarmingTemp`", SQLStatement1:="", SubType _
    11.         :=wdMergeSubTypeAccess
    12.     ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
    13. End Sub

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: App.Path in Word ?

    I just realized that Application.Path is the path to Word and not the document path.
    Use ActiveDocument.Path to get the directory where the document resides

    Another variation: Word.Documents(1).Path
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2004
    Location
    SouthWest
    Posts
    120

    Re: App.Path in Word ?

    Ok.....Can u tell me where I would put the ActiveDocument.Path? I tried replacing it with the Application.Path and it didnt work..... there seems to be two instance where it needs the directory of the db ...once in the mail merge sequence and another in the sql ....... How could I structure this? Thanks again!

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: App.Path in Word ?

    Try placing the Document(1).Path into a variable at the beginning of your procedure. Then replace the application.path with the var.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: App.Path in Word ?

    Can you re-paste in your procedure again, but when you do check the "Disable smilies in this post"?
    Seems we have an issue with the double quotes and line continuations.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Nov 2004
    Location
    SouthWest
    Posts
    120

    Re: App.Path in Word ?

    sure! Thanks!


    VB Code:
    1. Private Sub Document_Open()
    2. CommandBars("Mail Merge").Visible = True
    3.     ActiveDocument.MailMerge.OpenDataSource Name:= _
    4.         "C:\Program Files\Tracking Data\Tracking Data.mdb", ConfirmConversions:= _
    5.         False, ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
    6.         PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
    7.         WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _
    8.         Connection:= _
    9.         "Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=C:\Program Files\Tracking Data\Tracking Data.mdb;Mode=Read;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engin" _
    10.         , SQLStatement:="SELECT * FROM `FarmingTemp`", SQLStatement1:="", SubType _
    11.         :=wdMergeSubTypeAccess
    12.     ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
    13. End Sub

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2004
    Location
    SouthWest
    Posts
    120

    Re: App.Path in Word ?

    The code above is the working code. Its hardcoded however. I want it to find the db in the app folder of the program......

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: App.Path in Word ?

    I get an error that the string is longer then 255 characters. Do you get this error?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Nov 2004
    Location
    SouthWest
    Posts
    120

    Re: App.Path in Word ?

    the one that was hardcoded ...(C:Programfiles etc....) doesnt do that.... But when i put the ActiveDocument.Path it will give me that error..... Should I upload the Word form and db?

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: App.Path in Word ?

    Nah, its ok. I'm almost done. I took out some of the defaults that aren't needed.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: App.Path in Word ?

    Try this.
    VB Code:
    1. Private Sub Document_Open()
    2.     Dim sPath As String
    3.     CommandBars("Mail Merge").Visible = True
    4.     sPath = ActiveDocument.Path & "\Tracking Data.mdb"
    5.     MsgBox sPath
    6.     ActiveDocument.MailMerge.OpenDataSource Name:=sPath, ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
    7.     AddToRecentFiles:=False, Revert:=False, Format:=wdOpenFormatAuto, _
    8.     Connection:="Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Password='';Data Source=" & sPath & _
    9.     ";Mode=Read;", SQLStatement:="SELECT * FROM 'FarmingTemp'", SQLStatement1:="", SubType:=wdMergeSubTypeAccess
    10.     ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
    11. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Nov 2004
    Location
    SouthWest
    Posts
    120

    Re: App.Path in Word ?

    ok on that it gives me a message box telling me where the db is located. but doesnt continue the macro. ill attach the word form and the db so you can see what the default macro does..... it basically runs the mailmerge when you open the word template. like i said before its hardcoded to the c drive etc..... And i want it to find the db where ever it is located.....

    What you have is on the right spot just want to automated so the box doesnt show and continues to run the macro... here is all the stuff...

    Thanks a million for the help!
    Attached Files Attached Files

  13. #13
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: App.Path in Word ?

    I put the message box in so you can verify the path. Is the path correct?
    I'll take a look at you doc
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Nov 2004
    Location
    SouthWest
    Posts
    120

    Re: App.Path in Word ?

    yeah the path is correct! were right on just if the query or macro can continue were good!

  15. #15
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: App.Path in Word ?

    Just comment out the msgbox and see if that does it.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Nov 2004
    Location
    SouthWest
    Posts
    120

    Re: App.Path in Word ?

    When I take out the comment box it takes me to select the connection or db then the table etc.... the original macro I had took care of this it did everything automatically.......Did u get a chance to view the docs I uploaded?
    Thanks again for you help!

  17. #17
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: App.Path in Word ?

    Yes, it was doing that for mee too. I have it at home so I will take another look at it tonight.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  18. #18

    Thread Starter
    Lively Member
    Join Date
    Nov 2004
    Location
    SouthWest
    Posts
    120

    Re: App.Path in Word ?

    Thanks again For your Help!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width