Attachment macro in MSwords

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jamielowmp
    New Member
    • Nov 2006
    • 3

    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
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Originally posted by Jamielowmp
    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;

    Code:
    Private Sub CommandButton1_Click()
        Dim strFileName As String
        
        strFileName = SelectFile()
        Selection.InsertFile strFileName
    End Sub
    
    Function SelectFile() As String
    With Dialogs(wdDialogFileOpen)
        If .Display Then
            SelectFile = WordBasic.FilenameInfo$(.Name, 1)
        Else
            SelectFile = ""
        End If
    End With
    End Function

    Comment

    • Jamielowmp
      New Member
      • Nov 2006
      • 3

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

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        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.

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by Jamielowmp
          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.

          Comment

          • Jamielowmp
            New Member
            • Nov 2006
            • 3

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

            Comment

            Working...