Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Apr 2016
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Saving a word document from excel using some information from a userform.

    Hello,

    Not sure if this is even possible but I have a userform that once filled out populates a word document. I want it to also save the word document but do not want it to overwrite the last document. I have a textbox named stocktextbox in my userform that I would like it to save under that value. I want it to save in a file folder like C:\documents\problemtracker\"stocktextbox"? Can someone help me please. I have all other aspects of this working just the save part is where i am having my issue.'

    Thanks in advance

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    For that you could use Word's SaveAs2 method, with code like:
    .SaveAs2 FileName:="C:\documents\problemtracker\" & Me.stocktextbox.Value & ".docx", Fileformat:=wdFormatXMLDocument, AddToRecentFiles:=False
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. #3
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Cross-posted at: http://www.mrexcel.com/forum/excel-q...-userform.html

    Please read our policy on Cross-Posting in rule #14: http://windowssecrets.com/forums/faq...n#crossposting
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  4. #4
    New Lounger
    Join Date
    Apr 2016
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by macropod View Post
    For that you could use Word's SaveAs2 method, with code like:
    .SaveAs2 FileName:="C:\documents\problemtracker\" & Me.stocktextbox.Value & ".docx", Fileformat:=wdFormatXMLDocument, AddToRecentFiles:=False
    I tried that and this is what I got.

    Run-time error'438':
    Object doesn't support this property or method.

    Here is a copy of what the code looks like.

    Dim appWD As Object
    Dim strTMP1 As String
    strTMP1 = DealerComboBox.Value
    strTMP2 = LossTextBox.Value
    strTMP3 = StockTextBox.Value
    strTMP4 = YMMTextBox.Value
    strTMP5 = ClaimTextBox.Value
    strTMP6 = CommentsTextBox
    On Error Resume Next
    Set appWD = CreateObject("Word.Application")
    On Error GoTo 0
    With appWD
    .Visible = True
    .Documents.Open ("S:\ASR\FSS\Common Issue Reviews\Review.docx")
    .ActiveDocument.Bookmarks("LossDate").Range = strTMP2
    .ActiveDocument.Bookmarks("Location").Range = strTMP1
    .ActiveDocument.Bookmarks("LossDate2").Range = strTMP2
    .ActiveDocument.Bookmarks("Stock").Range = strTMP3
    .ActiveDocument.Bookmarks("Claim").Range = strTMP5
    .ActiveDocument.Bookmarks("YMM").Range = strTMP4
    .ActiveDocument.Bookmarks("Comments").Range = strTMP6
    .SaveAs2 Filename:="S:\ASR\FSS\" & Me.StockTextBox.Value & ".docx", FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False


    End With

    Thanks

  5. #5
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Well, if you looked in Word's VBA help, you'd see that the .SaveAs2 method requires a document reference, which in your case would mean prefixing it with .ActiveDocument.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

Posting Permissions

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