Results 1 to 10 of 15

Thread: VBA Macro To Create An Excel File With Same Sheet Name As Workbook Name

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,385
    Rep Power
    10
    Hi Flupsie,
    _ I assume by „Sheet1“ you mean the first “Tab” Counting from the Left. This can be referenced by it’s Item number , which is a consecutive count starting at 1 from the left and increasing by 1 as you count to the right. ( _.....you actually used the “shorthand” version of that yourself with the
    .Sheets(1).Name= ....
    .)

    Here the modified code:

    Code:
    '
     Sub CreateCSVFile() '   http://www.excelfox.com/forum/showthread.php/2123-Macro-to-crete-CSV-with-same-sheetname-as-xlsm-file
    'The path name:
    Dim MyPath As String: MyPath = "C:\Journal Templates\"
                'MyFileName = "Adjustment JNL.csv"
        If Not Right(MyPath, 1) = "\" Then MyPath = MyPath & "\"
       
        With ActiveWorkbook
        'The File name:
        Dim MyFileName As String: Let MyFileName = .Worksheets.Item(1).Name & ".csv" 'The Worksheets Collection Object is used referrencing by Item number which is a consecutive count starting at 1 from the left  and increasing by 1 as you count to the right. This Worksheet has the .Name Property applied to return the String Tab Name
                    '.Sheets(1).Name = "JNL"
         .SaveAs Filename:=MyPath & MyFileName, FileFormat:=xlCSV, CreateBackup:=False
         .Close False
        End With
    End Sub
    Alan
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  2. #2
    Member
    Join Date
    Aug 2012
    Posts
    40
    Rep Power
    0
    Quote Originally Posted by DocAElstein View Post
    Hi Flupsie,
    _ I assume by „Sheet1“ you mean the first “Tab” Counting from the Left. This can be referenced by it’s Item number , which is a consecutive count starting at 1 from the left and increasing by 1 as you count to the right. ( _.....you actually used the “shorthand” version of that yourself with the
    .Sheets(1).Name= ....
    .)

    Here the modified code:

    Code:
    '
     Sub CreateCSVFile() '   http://www.excelfox.com/forum/showthread.php/2123-Macro-to-crete-CSV-with-same-sheetname-as-xlsm-file
    'The path name:
    Dim MyPath As String: MyPath = "C:\Journal Templates\"
                'MyFileName = "Adjustment JNL.csv"
        If Not Right(MyPath, 1) = "\" Then MyPath = MyPath & "\"
       
        With ActiveWorkbook
        'The File name:
        Dim MyFileName As String: Let MyFileName = .Worksheets.Item(1).Name & ".csv" 'The Worksheets Collection Object is used referrencing by Item number which is a consecutive count starting at 1 from the left  and increasing by 1 as you count to the right. This Worksheet has the .Name Property applied to return the String Tab Name
                    '.Sheets(1).Name = "JNL"
         .SaveAs Filename:=MyPath & MyFileName, FileFormat:=xlCSV, CreateBackup:=False
         .Close False
        End With
    End Sub
    Alan
    Thanks for the help Alan. I need one small change. The sheet name is now correct, but I need the original workbook name i.e Adjustment JNL.csv

    Kindly amend your code to incorporate this



Similar Threads

  1. Replies: 4
    Last Post: 07-02-2013, 11:32 AM
  2. Replies: 4
    Last Post: 06-18-2013, 01:38 PM
  3. VBA To Create A New Workbook
    By cdurfey in forum Excel Help
    Replies: 9
    Last Post: 05-23-2013, 06:41 PM
  4. Excel VBA Macro To Open A File Through Browse Dialog Box
    By Safal Shrestha in forum Excel Help
    Replies: 2
    Last Post: 04-05-2013, 12:59 PM
  5. Replies: 1
    Last Post: 06-02-2011, 10:38 AM

Posting Permissions

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