hi!
I'm trying to create a macro in Microsoft Word to allow users to save a document and pass the name of the document in to Microsoft Access database.
here is a macro in Microsoft Word.
this is pretty much a copy of the solution I found the Microsoft's site
for some reason it does not work: the first part -saving file and selecting name is OK, but then it cannot establish a link with Microsoft Access database to pass file name.
to try it out, open Microsoft Word, from the file menu select "tools", -> "macros" -> "Create" and paste this code
----------------------------------------------------
Sub SaveAndAddFile()
Dim FileSelected As Variant
Dim openFile1 As FileDialog
Set openFile1 = Application.FileDialog(msoFileDialogSaveAs)
With openFile1
'Use the Show method to display the File Picker 'dialog box and return the user's action.
'The user pressed the action button.
If .Show = -1 Then
'Step through each string in the FileDialogSelectedItems collection.
For Each FileSelected In .SelectedItems
'This example simply displays the path in a message box.
MsgBox "The path is: " & FileSelected
Next FileSelected
'The user pressed Cancel.
Else
End If
End With
'run sub to insert filename into Microsoft Access
insertRef
'Set the object variable to Nothing.
Set openFile1 = Nothing
End Sub
Sub insertRef()
Dim Chan As Long
var1$ = FileSelected
Chan = DDEInitiate("MSaccess", "afterupdate;runSQL INSERT INTO table3 (f3) SELECT var1$ FROM none;")
DDETerminate Channel:=Chan
End Sub
--------------------------------------------------------
thank you
I'm trying to create a macro in Microsoft Word to allow users to save a document and pass the name of the document in to Microsoft Access database.
here is a macro in Microsoft Word.
this is pretty much a copy of the solution I found the Microsoft's site
for some reason it does not work: the first part -saving file and selecting name is OK, but then it cannot establish a link with Microsoft Access database to pass file name.
to try it out, open Microsoft Word, from the file menu select "tools", -> "macros" -> "Create" and paste this code
----------------------------------------------------
Sub SaveAndAddFile()
Dim FileSelected As Variant
Dim openFile1 As FileDialog
Set openFile1 = Application.FileDialog(msoFileDialogSaveAs)
With openFile1
'Use the Show method to display the File Picker 'dialog box and return the user's action.
'The user pressed the action button.
If .Show = -1 Then
'Step through each string in the FileDialogSelectedItems collection.
For Each FileSelected In .SelectedItems
'This example simply displays the path in a message box.
MsgBox "The path is: " & FileSelected
Next FileSelected
'The user pressed Cancel.
Else
End If
End With
'run sub to insert filename into Microsoft Access
insertRef
'Set the object variable to Nothing.
Set openFile1 = Nothing
End Sub
Sub insertRef()
Dim Chan As Long
var1$ = FileSelected
Chan = DDEInitiate("MSaccess", "afterupdate;runSQL INSERT INTO table3 (f3) SELECT var1$ FROM none;")
DDETerminate Channel:=Chan
End Sub
--------------------------------------------------------
thank you