Mar 17th, 2005, 05:11 PM
#1
Thread Starter
Lively Member
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:
Private Sub Document_Open()
CommandBars("Mail Merge").Visible = True
ActiveDocument.MailMerge.OpenDataSource Name:= _
[COLOR=Red]" & Application.Path & "\Tracking Data.mdb", ConfirmConversions[/COLOR]:= _
False, ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _
Connection:= _
"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" _
, SQLStatement:="SELECT * FROM `FarmingTemp`", SQLStatement1:="", SubType _
:=wdMergeSubTypeAccess
ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
End Sub
Mar 17th, 2005, 05:46 PM
#2
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Mar 17th, 2005, 06:27 PM
#3
Thread Starter
Lively Member
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!
Mar 17th, 2005, 06:35 PM
#4
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Mar 17th, 2005, 06:54 PM
#5
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Mar 17th, 2005, 06:57 PM
#6
Thread Starter
Lively Member
Re: App.Path in Word ?
sure! Thanks!
VB Code:
Private Sub Document_Open()
CommandBars("Mail Merge").Visible = True
ActiveDocument.MailMerge.OpenDataSource Name:= _
"C:\Program Files\Tracking Data\Tracking Data.mdb", ConfirmConversions:= _
False, ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _
Connection:= _
"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" _
, SQLStatement:="SELECT * FROM `FarmingTemp`", SQLStatement1:="", SubType _
:=wdMergeSubTypeAccess
ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
End Sub
Mar 17th, 2005, 07:00 PM
#7
Thread Starter
Lively Member
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......
Mar 17th, 2005, 07:06 PM
#8
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Mar 17th, 2005, 07:10 PM
#9
Thread Starter
Lively Member
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?
Mar 17th, 2005, 07:11 PM
#10
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Mar 17th, 2005, 07:23 PM
#11
Re: App.Path in Word ?
Try this.
VB Code:
Private Sub Document_Open()
Dim sPath As String
CommandBars("Mail Merge").Visible = True
sPath = ActiveDocument.Path & "\Tracking Data.mdb"
MsgBox sPath
ActiveDocument.MailMerge.OpenDataSource Name:=sPath, ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, Revert:=False, Format:=wdOpenFormatAuto, _
Connection:="Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Password='';Data Source=" & sPath & _
";Mode=Read;", SQLStatement:="SELECT * FROM 'FarmingTemp'", SQLStatement1:="", SubType:=wdMergeSubTypeAccess
ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Mar 17th, 2005, 07:43 PM
#12
Thread Starter
Lively Member
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
Mar 17th, 2005, 09:08 PM
#13
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Mar 17th, 2005, 09:10 PM
#14
Thread Starter
Lively Member
Re: App.Path in Word ?
yeah the path is correct! were right on just if the query or macro can continue were good!
Mar 17th, 2005, 09:35 PM
#15
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Mar 18th, 2005, 06:28 PM
#16
Thread Starter
Lively Member
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!
Mar 18th, 2005, 06:40 PM
#17
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Mar 18th, 2005, 06:59 PM
#18
Thread Starter
Lively Member
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
Forum Rules
Click Here to Expand Forum to Full Width