Consulting

Results 1 to 4 of 4

Thread: Solved: SaveAs

  1. #1
    VBAX Regular
    Joined
    Sep 2006
    Posts
    15
    Location

    Solved: SaveAs

    Hi folks,

    Iam trying to press a button and have my form saved in another place.

    Here is the code:

    [VBA] Private Sub cmdSpiral_Click()
    Dim strFilename As String

    strFilename = "d:/" & txtAccount.Text & ".doc"

    Me.SaveAs strFilename, wdFormatText
    End Sub[/VBA]

    I am receiving "Run time error 4198" command failed. any tips.

    T.I.A.

    Aaron

  2. #2
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi Aaron,

    When you say "form", are you talking about a document that you designed, or an actual userform that you designed in the VBE?

    If its a userform, you'll need to export it to file. If it's a document, I would think that modifying it to this (untested) should work:

    [vba] Private Sub cmdSpiral_Click()
    Dim strFilename As String

    strFilename = "d:/" & txtAccount.Text & ".doc"

    ThisDocument.SaveAs strFilename, wdFormatText
    End Sub[/vba]
    (Might be ActiveDocument instead of ThisDocument.)

    PS... I've edited your post to use our VBA tags. [uvba]a[/uvba]
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  3. #3
    VBAX Regular
    Joined
    Sep 2006
    Posts
    15
    Location
    I, for some reason created a template from scratch and used vba in it to perform several functions, such ensuring that certain fields are filled in prior to allowing the user to save the document/form

  4. #4
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    That is nice, but it hardly answered the question.

    "Me" would make most of us think userform.

    Ken is correct, if it is a document you are saving, it would be ActiveDocument.SaveAs.

Posting Permissions

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