467,161 Members | 912 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,161 developers. It's quick & easy.

Attachment macro in MSwords

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
  • viewed: 1319
Share:
5 Replies
1GB
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
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 8TB
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 8TB
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
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.

Similar topics

4 posts views Thread by Wald | last post: by
2 posts views Thread by knoak | last post: by
reply views Thread by Aquila Deus | last post: by
3 posts views Thread by TomislaW | last post: by
9 posts views Thread by deepaks85 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.