• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Save File Name with Cell Value

Sg2209

New Member
Hi Friends ,

i am trying to save my sheet ( Temp) as based on a cell value , there is a date in Cell J2, I need each time when sheet is getting emailed through Outlook , it should be send as per the name in Cell J2, Currently i have set it to the Current date , however i need this as per Cell Value , below is my code
Code:
Dim TempFilePath As String
Dim TempFileName As String

'Save the new workbook/Mail it/Delete it
    TempFilePath = Environ$("temp") & "\"
    TempFileName = Sheets("Do-Not-Change").Range("J2").Text
    ThisWorkbook.SaveAs Filename:=TempFilePath & "\" & TempFileName

please review and share the feedback where i am incorrect the above code .

thank you .
 
Try:

Code:
Dim TempFilePath As String
Dim TempFileName As String

    'Save the new workbook/Mail it/Delete it
    TempFilePath = Environ$("temp") & "\"
    TempFileName = Sheets("Do-Not-Change").Range("J2").Text & ".xlsm"
    ThisWorkbook.SaveAs Filename:=TempFilePath & TempFileName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
 
Still getting error subscript out of range on the below line

TempFileName = Sheets("Do-Not-Change").Range("J2").Text & ".xlsm"
 
Hi !

Check for a bad worksheet name in active workbook
or a bad cell value (error) …

If worksheet is in code workbook,
better is to use its codename instead of its name.
 
What Marc means is
upload_2018-2-9_21-11-26.png

so the code becomes:
Code:
Dim TempFilePath As String
Dim TempFileName As String

    'Save the new workbook/Mail it/Delete it
    TempFilePath = Environ$("temp") & "\"
    'TempFileName = Sheets("Do-Not-Change").Range("J2").Text & ".xlsm"
    TempFileName = Sheet3.Range("J2").Text & ".xlsm"
    ThisWorkbook.SaveAs Filename:=TempFilePath & TempFileName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
 
I'd also check what value is in cell J2
check it for leading or trailing spaces and non-printable characters
 
Back
Top