Export each Sheet to .bat format without Double Quotes

hamidxa

New Member
Joined
Oct 11, 2013
Messages
19
I have the following VBA code (below) that I am attempting to run against each of my 21 worksheets.
The idea is that each worksheet should get saved out as a .bat filetype - and simply contain the text exactly as it appeared in each respective worksheet.

The problem is, the text contained in the generated .bat files include quotes "" that were not in the actual worksheets themselves.

How do I get around this issue?

Here is my VBA code:
VBA Code:
Sub ExportSheetsToCSV()
    Dim xWs As Worksheet
    Dim xcsvFile As String
    For Each xWs In Application.ActiveWorkbook.Worksheets
        xWs.Copy
        xcsvFile = CurDir & "\" & xWs.Name & ".bat"
        Application.ActiveWorkbook.SaveAs Filename:=xcsvFile, _
        FileFormat:=xlCSV, CreateBackup:=False
        Application.ActiveWorkbook.Saved = True
        Application.ActiveWorkbook.Close
    Next
End Sub


Here is a sample of how the data should look
set curr_date=%DATE:~10,4%-%DATE:~4,2%-%DATE:~7,2%
echo %curr_date%"
command -k -g https://logintosite -u un -p pw data.source @"\\datasource\gvl\SHARED\Something Something Team\VendorX\Automation\XML\Master File.xml" -o "\\datasource.net\gvl\SHARED\Something Something Team\VendorX\Automation\Bat\Master File 2022-11-21.csv" -H

Versus how the above actually looks when ran through the VBA code:
"set curr_date=%DATE:~10,4%-%DATE:~4,2%-%DATE:~7,2%"
"echo %curr_date%"""

"command -k -g https://logintosite -u un -p pw data.source @""\\datasource\gvl\SHARED\Something Something Team\VendorX\Automation\XML\Master File.xml"" -o ""\\datasource.net\gvl\SHARED\Something Something Team\VendorX\Automation\Bat\Master File 2022-11-21.csv"" -H"


FYI - I have also tried changing the format to xlTextPrinter per:
Application.ActiveWorkbook.SaveAs Filename:=xTextFile, FileFormat:=xlTextPrinter, CreateBackup:=False

But it butchers my outputted .bat text, cutting off lines and starting new lines - thus rendering the code inoperative.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I tried your maco.
It works well and makes *.bat without any quotes "".
May I have your PC system name ? Windows ? or MAC ?
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top