Activate file with file name depending on cell value changed

Linda Lo

New Member
Joined
May 15, 2023
Messages
7
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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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,214,927
Messages
6,122,309
Members
449,080
Latest member
jmsotelo

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