By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,986 Members | 1,487 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,986 IT Pros & Developers. It's quick & easy.

Attachment macro in MSwords

P: 3
Hi there...
this is my first message in this community. I know there's a lot of benefits in VB macro but i'm not very good at programming (still a basic learner). I have an urgent task that requires me to do a command button for attaching a file in mswords. That means, i'm required to do a macro in an msword template such that when clicked, it automatically perform the same as 'Insert File' where user will browse for the correct file to attach.

I know its should be a simple task but i can't figure out how. Hope someone enlighten me. THANKS!

rgds,
Jamie
Nov 16 '06 #1
Share this Question
Share on Google+
5 Replies


100+
P: 1,646
Hi there...
this is my first message in this community. I know there's a lot of benefits in VB macro but i'm not very good at programming (still a basic learner). I have an urgent task that requires me to do a command button for attaching a file in mswords. That means, i'm required to do a macro in an msword template such that when clicked, it automatically perform the same as 'Insert File' where user will browse for the correct file to attach.

I know its should be a simple task but i can't figure out how. Hope someone enlighten me. THANKS!

rgds,
Jamie
Hi. Here is the code that will start you off;

Expand|Select|Wrap|Line Numbers
  1. Private Sub CommandButton1_Click()
  2.     Dim strFileName As String
  3.  
  4.     strFileName = SelectFile()
  5.     Selection.InsertFile strFileName
  6. End Sub
  7.  
  8. Function SelectFile() As String
  9. With Dialogs(wdDialogFileOpen)
  10.     If .Display Then
  11.         SelectFile = WordBasic.FilenameInfo$(.Name, 1)
  12.     Else
  13.         SelectFile = ""
  14.     End If
  15. End With
  16. End Function
  17.  
Nov 16 '06 #2

P: 3
Hey...thanks!!!!!
So, if i want to display the selected file as a link, i'll have to enhance the code with a "display as link" command right?
Nov 21 '06 #3

Expert 5K+
P: 8,434
Hi.

I see you got what you needed from willakawill. However, here's an observation that may serve you well in future.

The easiest way to get started with a macro in Word is to record it. Then you can go in and edit it. Give it a try some time, it gives you a big head-start.
Nov 21 '06 #4

Expert 5K+
P: 8,434
Hey...thanks!!!!!
So, if i want to display the selected file as a link, i'll have to enhance the code with a "display as link" command right?
Yeah, I believe it's an option on the InsertFile method.
Nov 21 '06 #5

P: 3
hi willakawill,
i've managed to get what i wanted by developing from your code u guided me from. Thanks so much!
Dec 12 '06 #6

Post your reply

Sign in to post your reply or Sign up for a free account.