Excel VB to Save Sheet as Filename

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • flickimp
    New Member
    • Dec 2006
    • 37

    #1

    Excel VB to Save Sheet as Filename

    Hi

    I have an excel file with 20 sheets.

    Now then... I am only interested in one Sheet (2 pages) and I want to save that to a particular folder.

    Also, the sheet is dependent on Cell D7 equalling a code...that in turn feeds all of the vlookups...you get the picture

    For this, I added a loop.[PLEASE SEE CODE BELOW]

    What should happen, is D7 should be populated by watever lies in W1...etc.
    It should then save the file based on A10 (which contains the Folder location and filename) ....then move onto the next code for D7 etc....thus looping.

    Now when i run it....it saves the file as FALSE and does not put it in the required location.....

    Even though the filename in A10= Q:\FolderA\Fold erB\FolderC\Fol derD\Cat

    Assuming that D7 = Cat

    When I run it, I get a file called FALSE in FolderC????

    Any ideas where I'm going wrong?


    _______________ _______________ _______________ _-
    CODE =

    Application.Dis playAlerts = False

    For i = 1 To 2

    Sheets("Summary Report Sheet").Select
    Range("D7").Val ue = Range("W" & 1 + i).Value
    Sheets("Summary Report Sheet").Copy
    ThisFile = Range("A10").Va lue
    ActiveWorkbook. SaveAs Filename = ThisFile
    ActiveWorkbook. Close
    Next i

    Application.Dis playAlerts = True
    MsgBox ("The Force is Strong")
    End Sub
  • ubentook
    New Member
    • Dec 2007
    • 58

    #2
    Is ThisFile declared as a String? It should be.
    Also, you can't have duplicate file names in a single folder.

    Comment

    Working...