Consulting

Results 1 to 12 of 12

Thread: Solved: word doc as attachement

  1. #1
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location

    Solved: word doc as attachement

    Hi all

    I have a button on an excel form to create an email and attach a word document that i am using as a template, this I am ok with and have working fine

    I also have a value in cell A1 say "12345" as an example

    My question is, is it possible to attach my template word document but for it to be named as per the value in cell A1?

    See the code below for how im getting things working so far

    [VBA] Dim AppOutlook As Object
    Dim StrAttach As String

    StrAttach = App.Path & "/Renewal.doc"
    Set AppOutlook = CreateObject("Outlook.application")

    With AppOutlook.CreateItem(olMailItem)
    'Send Message To
    .To = ""
    'Subject
    .Subject = ""
    'Body Text
    .Body = "Due for something or overdue etc......"
    'Display the message
    .Display
    .Attachments.Add StrAttach
    End With
    Set AppOutlook = Nothing[/VBA]

    Cheers

    Gibbo

  2. #2
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Do you mean you want to email 12345.doc instead of Renewal.doc? [vba]Dim AppOutlook As Object
    Dim StrAttach As String

    StrAttach = App.Path & Range("A1").Text & ".doc"
    Set AppOutlook = CreateObject("Outlook.application")

    With AppOutlook.CreateItem(olMailItem)
    'Send Message To
    .To = ""
    'Subject
    .Subject = ""
    'Body Text
    .Body = "Due for something or overdue etc......"
    'Display the message
    .Attachments.Add StrAttach
    .Display
    End With
    AppOutlook.Quit
    Set AppOutlook = Nothing[/vba]That should work fine then
    Matt

  3. #3
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    thanks matt,

    My renewal.doc is a template form and i will need to email it over and over, but i need if possible to rename the renewal.doc attachment to 12345.doc before i send the email

    cheers

    gibbo

  4. #4
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    What about something like this?
    Name App.Path & "/Renewal.doc" As App.Path & "/" & Range("A1").Text  & ".doc" 
    
    StrAttach = App.Path & "/" & Range("A1").Text  & ".doc"
    By the way I'm not 100% sure what you want here as you mention a template(.dot), but you are attaching a document (.doc).

  5. #5
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    Thanks Norie but I need to keep my original document called Renewal.

    I have a document called Renewal.doc. It is a template document but because im emailing it to folk i ve left it as a .doc instead of a .dot so I can rename it and send it as an attachement from my code

    So what I need is for the attachement to be renamed but the renewal.doc to remain as being called renewal.doc

    Using your method i can always rename it back after i ve sent it so it does solve my problem but was wondering what other methods are available to me.

    I know i can also copy the doc using and then kill my copy when sent

    [VBA]FileCopy App.Path & "\Renewal.doc", App.Path & "12345" & ".doc"[/VBA]

    thanks for your patience

    gibbo

  6. #6
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Hi Gibbo,

    Sorry about the delay, but it looks like you already got the answer I would have given (first FileCopy, then Kill).

    Matt

  7. #7
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    Thanks Matt

    I ll mark this as solved then

    Gibbo

  8. #8
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Gibbo

    There is a property of an Attachment called DisplayName, that allows you to set what is displayed below the attachment.

    I don't know if that will do what you want.

  9. #9
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    Norie

    How do I use this property?

    tried as per below but states it doesnt support this object?

    [VBA] .Attachments.Add TestDoc
    .Attachments.DisplayName "Attach Name"[/VBA]

  10. #10
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Gibbo,
    I haven't tried this, as I've never used the DisplayName property, but it should work:[vba] With .Attachments.Add(TestDoc)
    .DisplayName "Attach Name"
    End With[/vba]Matt

  11. #11
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Gibbo

    It's a property of an Attachment, not the Attachments collection.

    Try the code Matt posted, but I think you might need an = in there.
    [vba]
    With .Attachments.Add(TestDoc)
    .DisplayName="Attach Name"
    End With [/vba]

  12. #12
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Wow, forgot an equals sign Sorry about that, hadn't had much coffee yet at that point :P

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •