简体   繁体   中英

Macro to save Excel sheet with file name and path from cell values

I'm trying to create a macro button that will save the active sheet as a pdf, go to a specific folder(based on cell value), and have a file name based on cell value. What would be the VBA code to save a the active excel sheet based on values in a cell?

Example:

(First part of Path name) C:\User\Documents\

The final part of the path will be the folder name which is in cell B2.

The file name I need to auto create as "Value of B1 + XXXXX(static text) + Value of D2"

Example Output

Save to: C:\User\Documents*Folder Name from B1*

File Name: Text from B1 + "Settlement WE" + Value from D2

Please help.

To create your file name:

Dim vn as String, fn as String

vn = "some string"
fn = Range("B1") & vn & Range("D2")

fn would be your final output (unclear if D2 includes file extension or not)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM