hey
I wonder can anyone help me. I'm trying to write a macro that allows a user to browse for a file and then inserts the file path and name as a link in an emails body.
I have code in a function (but I don't think it will work) that opens an instance of Word openfile dialog, and allows user to browse and select the file. The problem is that the function returns empty! Any help? Thanks
This is my code:
Function GetFolderPathWithWord()
Dim objWord As Word.Application
Dim dlg As Object 'Dialogs.wdDialogFileOpen
Dim lngWidth As Long
Dim lngHeight As Long
Dim objOL As Outlook.Application
Dim objOLWindow As Object
On Error Resume Next
' get active Outlook window
Set objOL = CreateObject("Outlook.Application")
Set objOLWindow = objOL.ActiveWindow
' start Word if necessary
Set objWord = GetObject(, "Word.Application")
If objWord Is Nothing Then
Set objWord = CreateObject("Word.Application")
End If
If Not objWord Is Nothing Then
' get current Word window dimensions
lngWidth = objWord.Width
lngHeight = objWord.Height
' reduce size of Word window
objWord.Width = 0
objWord.Height = 0
' switch to Word
objWord.Activate
' show file dialog and handle users choice
Set dlg = objWord.Dialogs(wdDialogFileOpen)
With dlg
.InitialView = msoFileDialogViewList
If .Display <> 0 Then
GetFolderPathWithWord = dlg.SelectedItems(1)
Else
GetFolderPathWithWord = "User cancelled dialog"
End If
End With
Else
GetFolderPathWithWord = "Could not open Word"
End If
Crabback
I wonder can anyone help me. I'm trying to write a macro that allows a user to browse for a file and then inserts the file path and name as a link in an emails body.
I have code in a function (but I don't think it will work) that opens an instance of Word openfile dialog, and allows user to browse and select the file. The problem is that the function returns empty! Any help? Thanks
This is my code:
Function GetFolderPathWithWord()
Dim objWord As Word.Application
Dim dlg As Object 'Dialogs.wdDialogFileOpen
Dim lngWidth As Long
Dim lngHeight As Long
Dim objOL As Outlook.Application
Dim objOLWindow As Object
On Error Resume Next
' get active Outlook window
Set objOL = CreateObject("Outlook.Application")
Set objOLWindow = objOL.ActiveWindow
' start Word if necessary
Set objWord = GetObject(, "Word.Application")
If objWord Is Nothing Then
Set objWord = CreateObject("Word.Application")
End If
If Not objWord Is Nothing Then
' get current Word window dimensions
lngWidth = objWord.Width
lngHeight = objWord.Height
' reduce size of Word window
objWord.Width = 0
objWord.Height = 0
' switch to Word
objWord.Activate
' show file dialog and handle users choice
Set dlg = objWord.Dialogs(wdDialogFileOpen)
With dlg
.InitialView = msoFileDialogViewList
If .Display <> 0 Then
GetFolderPathWithWord = dlg.SelectedItems(1)
Else
GetFolderPathWithWord = "User cancelled dialog"
End If
End With
Else
GetFolderPathWithWord = "Could not open Word"
End If
Crabback