jeffcrtra

New Member
Joined
Oct 21, 2010
Messages
10
Hey folks, greetings!

I have been dealing with this issue for a while already.

Because of my work I must create files and save them with variable name (date of creation), the format should be CSV. I made a macro that makes all the work for me, taking the name from a specific cell and saving the file with a variable name... wonderful!! BUT.... I have not been able to make the macro open the CSV with a variable name.

I need the macro to open to replace a character and close again, this part is succesful, but I just can't make it to open a variable filename.

What I have been doing is that the macro save it with a specific name, reopen and work it fine but at the end I manually gotta change the name.

Give me a help!! I really need this so bad! it is soooo time consuming. I'm using Excel 2007, by the way.
Thank you.

Here is the part of the code I'm using:


Sheets("Stock").Select
ChDir ThisWorkbook.Path
ThisWorkbook.SaveAs Filename:="Stk_2010-xx-xx.psv", _
FileFormat:=xlCSV, CreateBackup:=False

Sheets("Sales").Select
ChDir ThisWorkbook.Path
ThisWorkbook.SaveAs Filename:="Sls_2010-xx-xx.psv", _
FileFormat:=xlCSV, CreateBackup:=False

ChDir ThisWorkbook.Path
ThisWorkbook.SaveAs Filename:="back_up.xlsx", CreateBackup:=False

Workbooks.Open Filename:=ThisWorkbook.Path & "\Stk_2010-xx-xx.psv"

Cells.Replace What:="/", Replacement:="-", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Workbooks.Open Filename:=ThisWorkbook.Path & "\Sls_2010-xx-xx.psv"

Cells.Replace What:="/", Replacement:="-", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Presumably the xx-xx in Stk_2010-xx-xx.psv are the month and day numbers with leading zeroes, but you haven't said what determines this. Is it today's date? If so, try:

"\Stk_2010-" & Format(Date, "mm-dd") & ".psv"

If not, what is the logic for determining xx-xx?
 
Upvote 0
Hey John,
Thank you so much for replying.
Actually the date should is not today's, but a previous date. You see the customer is supposed to report the product`s stock every week, so this week he'll report last week`s stock, and so on.
I manage to place the date from a cell value int he file name but I'm still unable to reopen the csv file.
 
Upvote 0
I'm guessing it might have something to do with the

Code:
ThisWorkbook.Path

as this can change depending on which workbook is open.
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

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