Setting Word Startup Path from VB

S

Steve Weise

I currently have an Access 2000 DB that runs VB 6.0 code
to open up a Word Session and then execute a macro:
1) Dim oAppPrint As Object
2) Set oAppPrint = CreateObject("Word.Application")
3) oAppPrint.Run MacroName:="xxx"

I need to be able to set the Word startup path prior to
the macro(Step #3) being executed.

In Word VBA, the command is this:
Options.DefaultFilePath(Path:=wdStartupPath) = PathName

How does this translate into VB?

Thanks.
 
R

Robert

Here is some code I've used to send various startup parameters to Word
from VB. I'm using VB App.Path to set the path to my template and
actually opening that template from VB.

If you instead want to pass the path in as a parameter to the macro,
the line beginning "objDoc.StartHere CONNECT_STRING..." shows how I do
that. In Word I have a Sub routine called StartHere that is called
from the VB app. From there Word takes over and completes the task.

===========================================
basWord Module:

Private mobjWord As Word.Application

Public Sub PrintAppointment(CONNECT_STRING as string, lngPatientID As
Long, lngAppointmentID As Long)
Dim objDoc As Word.Document
Dim strTemplate As String
Dim strPath As String
Dim strConnectString As String

strPath = App.Path & "\"
strTemplate = strPath & "UnifiedPatientInformationForm1.dot"

Set mobjWord = CreateObject("Word.Application")
Set objDoc = mobjWord.Documents.Add(strTemplate, False,
wdNewBlankDocument, False)

objDoc.Activate
objDoc.StartHere CONNECT_STRING, lngPatientID, lngAppointmentID

mobjWord.Visible = True
Set mobjWord = Nothing
End Sub

=======================================

Word "Macro" called from VB - actually just a procedure since macros
by definition can't take parameters:

Public Sub StartHere(strConnect As String, lngPatientID As Long,
lngAppointmentID As Long)
On Error GoTo err_handler
Set mcnn = New ADODB.Connection
With mcnn
.ConnectionString = strConnect
.CursorLocation = adUseClient
.Open
End With
Call FillPatient(lngPatientID)
''' call other stuff
err_handler:
On Error Resume Next
mcnn.Close
Set mcnn = Nothing
Exit Sub
End Sub

Robert
 

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