none
macro to open and save as a value in a cell RRS feed

  • Question

  • How can I create a macro (I've named it Test) that will:

    1.bring up the open dialogue box (to allow the user to choose a file)

    2.save the file, with the file name determined by the text in cell A3 in .xlsx format

    I have two pieces code that seem to work individually, but not together:

    Dim strFileName As String

      strFileName = Application.GetOpenFilename

      If strFileName = "False" Then Exit Sub

      MsgBox strFileName

    ThisFile = Range("A3").Value

     ActiveWorkbook.SaveAs Filename:=ThisFile

    

    Thanks for the help!


    • Edited by cjf2002 Thursday, February 26, 2015 10:32 PM
    Thursday, February 26, 2015 10:32 PM

All replies

  • Hi

    With very little change, this works for me. I just declared your last variable. (thisFile)

    Sub test()
        Dim strFileName As String, thisFile As String
        strFileName = Application.GetOpenFilename
        If strFileName = "False" Then Exit Sub
        MsgBox strFileName
        thisFile = Range("A3").Value
        ActiveWorkbook.SaveAs Filename:=thisFile
    End Sub


    Cimjet

    • Proposed as answer by Cimjet Saturday, February 28, 2015 1:11 PM
    Thursday, February 26, 2015 11:15 PM