Log in

View Full Version : [SOLVED:] Problem with VBA in Excel - following code giving me an error



AdamCavco
06-12-2024, 11:22 AM
' Get the filename from a specific cell, for example, cell A1
CellValue = ThisWorkbook.Sheets("FORM").Range("D14" & "-" & "E8").Value (<--------THIS ONE)
' Combine folder path and cell value as the file name
FileName = CellValue & ".xlsm"
' Combine folder path and file name
FilePath = FilePath & FileName
' Save the active workbook with the specified file path
ThisWorkbook.SaveAs FilePath

This code is supposed to take two values from the excel spreadsheet and place them in the name of the newly saved file.
I am getting an error from the code above where it says THIS ONE
The file will be named NAME-20240612.xlsm
Can anyone help... Thanks Adam

p45cal
06-12-2024, 12:11 PM
Either:
CellValue = ThisWorkbook.Sheets("FORM").Range("D14").Value & "-" & ThisWorkbook.Sheets("FORM").Range("E8").Valueor
With ThisWorkbook.Sheets("FORM")
CellValue = .Range("D14").Value & "-" & .Range("E8").Value
End With

AdamCavco
06-12-2024, 12:26 PM
Well that worked perfectly. I thought using the "ThisWorkbook...." twice would only pickup one value.
You are awesome thank you so much!!! :) :clap::clap::clap: