Consulting

Results 1 to 3 of 3

Thread: Save workbooksheet as .CSV with some variables

  1. #1
    VBAX Newbie
    Joined
    Apr 2019
    Posts
    2
    Location

    Save workbooksheet as .CSV with some variables

    Hi all, I'm Roland and I'm new to this forum & VBA, hope someone can help me with this challenge.

    I've got a workbook with multiple sheets, which is used to facilitate an operational process for a warehousing activity. I'm almost done with the "tool" except for one more thing.
    I am looking for a vba code to save the sheet called "Input CW1" as CSV. This is easy with a regular code, however I would like to provide the operations with some options to improve the processing. These required options are as follows:

    - I want the file to have the text in cell B2 of tab "Output CW1" as title. So “text B2.csv”.
    - I want the file to be saved in the location that is put in cell B3 of the tab "Output CW1".

    The macro should be attached then to the button in the tab “Output CW1”, so the macro has to be setup so it switches between tabs.

    Since I have little to zero knowledge of VBA I hope someone can support me over here.

    Roland
    Attached Files Attached Files

  2. #2
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,197
    Location
    Hi Roland, welcome to the forum.

    Maybe something like this would help:
    Sub SaveCSV()    
        Dim flName As String, flPath As String
        Dim strFullname As String
        
        flPath = Sheet4.Range("B3").Value
        flName = Sheet4.Range("B2").Value
        
        strFullname = flPath & flName
        
        Application.DisplayAlerts = False
        Sheets("Input CW1").Copy
        ActiveWorkbook.SaveAs Filename:=strFullname, FileFormat:=xlCSV, CreateBackup:=True
        ActiveWorkbook.Close
        Application.DisplayAlerts = True
    
    End Sub
    Your file path will need to end with a \ for it to work.

    Hope this helps
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  3. #3
    VBAX Newbie
    Joined
    Apr 2019
    Posts
    2
    Location
    That works, many thanks

Posting Permissions

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