A macro for opening and automatically filling in dialogue boxes

L

Lars P

I would like to make a macro in Word that opens the object
dialogue box, automatically selects a specific icon for
the object (the same icon for all the objects) and opens
the folder where the object files will be found. The only
thing the user of the macro will have to do, is to select
the object file it self.

Since I have very little experience with Visual Basic, my
efforts have so far failed. If anyone could lead me in the
right direction, I would be very thankful.

With Dialogs(wdDialogInsertObject)
.LinkToFile = True
.DisplayAsIcon = True
.IconFileName = "D:\ikoner\093.ICO"
.Show
End With

..only leads to "run-time error 438"

Regards
Lars P
 
D

Doug Robbins - Word MVP

Here's an exchange from Perry Lima that my help you:

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

Perry said:
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


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?


--
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
 

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