Activate file with file name depending on cell value changed

Linda Lo

New Member
Joined
May 15, 2023
Messages
9
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I am a fresh VBA learner. I have a problem in running the following macro. Could someone help me to point out?
Before I run it on 1st day and save as "20230515 HKD (with FMS new version upload).xlsm". I will run it again in next day and I need to add cell value before the file name in order to activate it when running it because of file name changed.

1st date run:

Windows("HKD (with FMS new version upload).xlsm").Activate

Dim FPath As String

Dim FDate As String

Dim FName As String

Cells(1, 4).Value = "=TEXT(RC[-1],""yyyymmdd"")"

FPath = "H:\TEMP\BEN\!PAU\PAU Sheet"

FDate = Cells(1, 4).Value

FName = " HKD (with FMS new version upload)"

ActiveWorkbook.SaveAs Filename:=FPath & "\" & FDate & FName

I found a error when 2nd date run, "20230515" will be the format value of Range("C1") in "20230515 HKD (with FMS new version upload).xlsm" file.

2nd date run:

Dim FileDate As String

FileDate = Range("C1").Value

Range("D1") = "=TEXT(C1,""YYYYMMDD"")"

Windows("FileDate" & " " & "HKD (with FMS new version upload)" & ".xlsm").Activate

Thanks a lot.

Linda
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Is there any chance that you can provide a link to the workbook? Fake data is fine. I'll try to help you get the code setup. Use the link icon at the top of the message box. You can post part of a worksheet with Mr. Excel's addin XL2BB. See HERE.
 
Upvote 0

Forum statistics

Threads
1,223,712
Messages
6,174,031
Members
452,542
Latest member
Bricklin

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