Hello There,
Hope all are fine. There is something that turned my head down. Please.
I have a worksheet, the data range is A3:O1000.
Now I have to save data in two formats (. text & .xlsx) in a specific location with the same file name (File Name based on cell Value= The value in A1 as Name, with C1 as Entry Number and E1 as date), I have to use one command button to do the job. The text file must create in "pipe delimited" format (no space) from range A4 to the last data row. I am using the below code for a text file, which creates a "pipe delimited" format with space.
and the .xlsx file creates from A3 to the last data row. I am Using the below code.
The file creates but I had to save it manually to my specific location. How to merge the code into one. When the button clicks and saves two files to a specific location with a specific file name. Any suggestion or help will be highly appreciated.
Thanks in advance.
Hope all are fine. There is something that turned my head down. Please.
I have a worksheet, the data range is A3:O1000.
Now I have to save data in two formats (. text & .xlsx) in a specific location with the same file name (File Name based on cell Value= The value in A1 as Name, with C1 as Entry Number and E1 as date), I have to use one command button to do the job. The text file must create in "pipe delimited" format (no space) from range A4 to the last data row. I am using the below code for a text file, which creates a "pipe delimited" format with space.
VBA Code:
Sub InventoryData_Button1_Click()
Dim UsedRows As Long
Dim UsedColumns As Long
Dim i As Long, j As Long
'// Define a suitable file name
Open "E:\1. Inventory\Inventory.txt" For Output As #1
With ActiveSheet
UsedRows = .UsedRange.Rows.Count
UsedColumns = .UsedRange.Columns.Count
For i = 4 To UsedRows + 2
For j = 1 To UsedColumns - 1
Print #1, .Cells(i, j); "|";
Next j
Print #1, .Cells(i, UsedColumns)
Next i
End With
Close #1
MsgBox "Finished...", vbInformation
End Sub
and the .xlsx file creates from A3 to the last data row. I am Using the below code.
VBA Code:
Sub InventoryData_Button3_Click()
Set NewBook = Workbooks.Add
Workbooks("Inventory.xlsx").Worksheets("Data").Range("A3:O1000").Copy
NewBook.Worksheets("Sheet1").Range("A1").PasteSpecial (xlPasteValues)
NewBook.SaveAs FileName:=NewBook.Worksheets("Sheet1").Range("E3").Value
End Sub
The file creates but I had to save it manually to my specific location. How to merge the code into one. When the button clicks and saves two files to a specific location with a specific file name. Any suggestion or help will be highly appreciated.
Thanks in advance.