Equivilent of Application.GetOpenFilename

S

Simon Tonkin

In Excel I used the following to get the user to browse for a filename (full path)

stfilename = Application.GetOpenFilename _
("Excel Files (*.xls),", 2, "Select File to Paste Path", , False)

In word is there a way to do the same thing? That is get the user to browse for a file and then select it so I can attached that file to an email?

Simon.
 
W

Word Heretic

G'day Simon Tonkin <[email protected]>,

activedocument.fullname

Steve Hudson
Word Heretic Sydney Australia
Tricky stuff with Word or words

Email: WordHeretic at tpg.com.au


Simon Tonkin was spinning this yarn:
 
S

Simon Tonkin

Unfortuately I don't want the active documents name I want the user to browse for a PDF file to attach. That way I can get the data for the subject from the word document and attach the PDF file. Any ideas on that

Simon.
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Simon,

Use

Dim PDFfile As String
With Dialogs(wdDialogFileOpen)
.Display
If Not WordBasic.FilenameInfo$(.Name, 1) = "" Then
PDFfile = WordBasic.FilenameInfo$(.Name, 1)
MsgBox PDFfile
Else
MsgBox "Action cancelled by user", vbExclamation, "Cancelled"
Exit Sub 'or other appropriate "undo" stuff...
End If
End With


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
P

Perry

Office XP and onwards, there's a new fileopen dialog
like examplified below.
FileDialog (look it up in Help)

It will attach the multiselect items to an email message
as well, as that was what you requested.

Sub oltest()
Dim ol As New Outlook.Application
Dim mi As Outlook.MailItem

Dim d As FileDialog
Set d = Application.FileDialog(msoFileDialogOpen)
d.Show
Set mi = ol.CreateItem(olMailItem)

For x = 1 To d.SelectedItems.Count
With mi
.To = "(e-mail address removed)"
.Attachments.Add d.SelectedItems(x)
.Display
End With
Next

End Sub

Krgrds,
Perry

Simon Tonkin said:
Unfortuately I don't want the active documents name I want the user to
browse for a PDF file to attach. That way I can get the data for the
subject from the word document and attach the PDF file. Any ideas on that?
 
P

Perry

I've adapted the code to prompt PDF files only.
Adjustments are indicated '<<<

Dim ol As New Outlook.Application
Dim mi As Outlook.MailItem

Dim d As FileDialog
Set d = Application.FileDialog(msoFileDialogFilePicker) '<<<

d.Filters.Add "PDF files", "*.pdf", 2 '<<<<<<<
d.FilterIndex = 2 '<<<<<<<
If d.Show Then '<<<<
Set mi = ol.CreateItem(olMailItem)

For x = 1 To d.SelectedItems.Count
With mi
.To = "(e-mail address removed)"
.Attachments.Add d.SelectedItems(x)
.Display
End With
Next
End If
End Sub

Krgrds,
Perry
 

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