application.saveasfilename not working

grabrail

Board Regular
Joined
Sep 6, 2010
Messages
128
Office Version
  1. 365
Platform
  1. Windows
Hi

I have a strange problem that has just started occuring.

I have a workbook that has a button coded to save the file as a specific name. This button has always worked, but for some reason today is not working as expected.

basically what the button does, is checks somes cells on a worksheet for multiple values, if they are blank then the save as name is listed as "unkown, unknown, unknown"
if the cells contain data, then the save as name is made up of the values of those cells.

Currently, if the cells are blank this is working fine.

However if the cells are populated, when the save as box comes up the save as name is completely blank, where it should have the suggested name showing.

here is my code

VBA Code:
Sub Button9_Click()
    Dim ActSheet As Worksheet
    Dim ActBook As Workbook
    Dim CurrentFile As String
    Dim NewFileType As String
    Dim NewFile As String
    Dim regNo As String
    Dim insDate As String
    Dim inspector As String
    'Dim operator As String
    Dim checkbox11 As checkbox

Set checkbox10 = ActiveSheet.CheckBoxes("Check Box 10")


    Application.ScreenUpdating = False    ' Prevents screen refreshing.

    CurrentFile = ThisWorkbook.FullName

    NewFileType = "Excel Files 2007 (*.xlsm), *.xlsm," & _
               "All files (*.*), *.*"

   
    If IsEmpty(Sheets("Title Page").Range("A17").Value) Then
        operator = "Unknown Operator"
    Else
        operator = Sheets("Title Page").Range("A17").Value
    End If
   
    If IsEmpty(Sheets("Title Page").Range("A29").Value) Then
        insDate = "Unknown Date"
    Else
        insDate = Replace(Sheets("Title Page").Range("A29").Value, "/", "-")
    End If
   

   

    If IsEmpty(Sheets("Title Page").Range("A34").Value) Then
        inspector = "Unknown Inspector"
    Else
        inspector = Sheets("Title Page").Range("A34").Value
    End If
   

    initialname = operator & " - " & _
        insDate & " - " & _
        inspector & " - " & " GC"
        'regNo & " - " & _

    MsgBox (initialname)

    NewFile = Application.GetSaveAsFilename( _
        InitialFileName:=initialname, _
        fileFilter:=NewFileType)
       
        MsgBox (NewFile)

    If NewFile <> "" And NewFile <> "False" Then
        ActiveWorkbook.SaveAs Filename:=NewFile, _
            FileFormat:=52, _
            Password:="", _
            WriteResPassword:="", _
            ReadOnlyRecommended:=False, _
            CreateBackup:=False

    Set ActBook = ActiveWorkbook
        Workbooks.Open NewFile

    End If
   
    checkbox10.Value = True
    checkbox10.Caption = "File Saved - " & Format(Date, "dd/mm/yyyy")
    Application.ScreenUpdating = True

End Sub

The msgbox (initialname) shows the correct values as expected, the Msgbox(Newfile) pops up with False)
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
I amanged to figure this one out. The problem was caused by one of our team using a full stop in one of the fields, for some reason when they did this it stopped the code working. Once I removed the full stop from the field it was all working again.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

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