+ Reply to Thread
Results 1 to 2 of 2

VB to save word doc with a filename just copied from an Outlook email

  1. #1
    Registered User
    Join Date
    07-09-2011
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    2

    VB to save word doc with a filename just copied from an Outlook email

    Hi,

    I have emails going to Outlook and I want to create a macro to copy part of the text and paste into a table in a word document, then 'save as' using one part of the text as the filename. I'd be grateful if someone could help me.

    This is what I have:
    "Sub Page()
    Selection.Copy
    Windows("Page").Activate
    ActiveDocument.Tables(1).Cell(Row:=1:6, Column:=2).Range.Select
    Selection.Paste
    Selection.Style = ActiveDocument.Styles("Normal")
    ActiveDocument.Tables(1).Cell(Row:=2, Column:=2).Range.Select
    ActiveDocument.SaveAs FileName:="'Selection.Paste'.docx", FileFormat:= _ wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _:=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _SaveAsAOCELetter:=False
    End Sub"

    Problem 1: If the VB code could auto select the text from the email that would be great but just to start off I'd be happy to select this first myself.

    Problem 2:
    It doesn't seem to go to the document and paste - I get an error. The code to select the table in the doc and then paste is wrong...

    Problem 3: It does not save, and if it did it would not be from the selection that it should be using. (btw, The text in row 2, column 2 is just a four-digit number...)

    Could anyone correct this for me..?

    Thanks!

  2. #2
    Registered User
    Join Date
    07-09-2011
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: VB to save word doc with a filename just copied from an Outlook email

    just to make this a bit easier to understand, I am looking for the code to:
    1. Copy the content of an email (or that which is selected by the user... easy)
    2. Take this content to a word document (doc name will always be the same and already open) and paste into a table within the doc (ideally selecting to paste into one column of the table automatically). The table has 2 columns and 6 rows, but I am only filling 1 column.
    3. Then save the doc with a filename, which is taken from the content (of row 2 of the table)
    I just can't get a grip of the VB to actively select the content and to save as with a dynamic filename taken from a cell of the table.

    Any advice for this relatively simple bit of code would be much appreciated...

    Chris

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1