Consulting

Results 1 to 4 of 4

Thread: need help in writting VBA Code to save file sequentially after each loop

  1. #1

    need help in writting VBA Code to save file sequentially after each loop

    good day,
    so I'm not a coder by any stretch of my imagination but I've inherited a workbook that allows me run thousands rows of data, the VBA code transposes data from a sheet into another sheet that performs various calculations based on each row of data (it loops and performs the same function until the last row):at the end of the VBA code it performs a print function, now instead of printing I'd like it to save as a copy (preferably pdf) in sequential files in a specified folder.

    The VBA coding currently ends with

    shDest.PrintOut 'COPIES:=2

    My poor attempt to VBA code a file save as option is below.

    Dim filepath As String
    Dim filename As String
    Dim filepatharch As String
    Dim filedate As String
    Dim filelist As String

    filedate = Format(Now, "MMDD01.")
    filepath = "\\C:\Users\PTX\Desktop\FileDrop"
    tdfilename = "TD" & filedate & filelist & ".xls"
    Sheets("TDflatfile").Copy
    ActiveWorkbook.SaveAs filename:="\\C:\Users\PTX\Desktop\FileDrop"" & tdfilename, FileFormat:=xls,"

    Any ideas or suggestions would be greatly appreciated.

  2. #2
    VBAX Tutor MINCUS1308's Avatar
    Joined
    Jun 2014
    Location
    UNDER MY DESK
    Posts
    254
    Here is a great reference for the .SaveAs method: https://msdn.microsoft.com/en-us/vba...s-method-excel
    - I HAVE NO IDEA WHAT I'M DOING

  3. #3
    VBAX Tutor MINCUS1308's Avatar
    Joined
    Jun 2014
    Location
    UNDER MY DESK
    Posts
    254
    What is FileList? the variable is not defined?
    - I HAVE NO IDEA WHAT I'M DOING

  4. #4
    VBAX Tutor MINCUS1308's Avatar
    Joined
    Jun 2014
    Location
    UNDER MY DESK
    Posts
    254
    Sub InterestingTest()
         '...
         'YOU PROBABLY HAVE STUFF BEFORE THE LOOP
         '...
         
         'THEN YOUR LOOP STARTS
         'NOTE THE VARIABLE 'i'**
         For i = 1 To 10
              'YOULL HAVE WHAT EVER HAPPENS IN YOUR LOOP
              '...
              
              'THEN INSTEAD OF PRINTING YOU WILL HAVE SOMETHING LIKE THE FOLLOWING:
              Dim FilePath As String
              Dim FileDate As String
              Dim FileList As String
              Dim FileName As String
              Dim FilePathArch As String
              
              FilePath = "\\C:\Users\PTX\Desktop\FileDrop\"
              FileDate = Format(Now(), "MMDD01.")
              FileList = i   '**HERE IS WHERE THE INCREMENTAL FILE NAMING COMES INTO PLAY**
              FileName = "TD" & FileDate & FileList & ".pdf"
              
              Sheets("TDflatfile").Copy
              ActiveWorkbook.SaveAs FileName:=FilePath & FileName
              
              'YOU WILL PROBABLY HAVE THINGS AFTER YOU SAVE [PRINT]
              '...
              
              'AND THEN THE LOOP WILL 'LOOP'
         Next i
         
         'YOU WILL PROBABLY HAVE THINGS AFTER THE LOOP
         '...
         
    End Sub
    - I HAVE NO IDEA WHAT I'M DOING

Posting Permissions

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