Code stopped working

jmk15315

Board Regular
Joined
Nov 7, 2021
Messages
73
Office Version
  1. 2013
  2. 2010
Platform
  1. Windows
Good morning. I am hoping someone might be able to help me out with this issue. I have been using the code below for a while now and it has performed flawlessly. Now out of the blue, it is not working the same way.
Yes, the code still performs the actions, but it has stopped building the file name based on the specified sheet, cell values. It simply forces me to enter a name for the file it is creating. At face value this is still functioning, however in order to maintain our naming structure, it does not populate the information as intended.

Any thoughts?

VBA Code:
Private Sub CommandButton105_Click()

   Dim strPath As String
   Dim saveAsFilename As Variant
   Dim tmpFileName As String
   Dim strPathFolder As String

' GENERATE SYSTEM PART NUMBER (Sheet Uses VLOOKUP)
    
    ActiveWorkbook.Unprotect (CAT_PROTECT)
    
        Sheets("System Numbering").Visible = True
        Sheets("System Numbering").Select
        Sheets("System Numbering").Range("AJ4").Select
        Selection.Copy
        Sheets("System Numbering").Range("AJ5").Select
        ActiveSheet.Paste
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
        Sheets("System Numbering").Visible = False
        Sheets("Summary").Select
    
    ActiveWorkbook.Protect (CAT_PROTECT)
    
        UserForm1_LIGHTWELD_COBOT_B.TextBox115.Visible = True

    Sheet1.Select
    
' SAVE QUOTE AS PDF
    saveAsFilename = Application.GetSaveAsFilename( _
        InitialFileName:=Application.DefaultFilePath & "\" & Sheet1.Range("B5").Value & "-" & Sheet1.Range("C5").Value & "-" & Sheet1.Range("B3").Value & "-FIRM" & "- COBOT-SYSTEM (LightWELD 2000-XR)", _
        FileFilter:="PDF File (*.pdf), *.pdf", _
        Title:="Save")
        
    If saveAsFilename = False Then Exit Sub
        
    ActiveWorkbook.Unprotect (CAT_PROTECT)
    Sheets("COBOT-QUOTE (5)").Visible = True
    Sheets("COBOT-QUOTE (5)").ExportAsFixedFormat Type:=xlTypePDF, Filename:=saveAsFilename, _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
    Sheets("COBOT-QUOTE (5)").Visible = False
    ActiveWorkbook.Protect (CAT_PROTECT)

    MsgBox "Success - Your completed quote has been save to: " & saveAsFilename & "'.", vbInformation
     
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
You could try adding some debug code to see why your file name is not being built from cell data.
VBA Code:
    ' SAVE QUOTE AS PDF
    Dim FilePath As String
    Dim R As Range
    
    Set R = Sheet1.Range("B5")
    If Trim(R.Value) = "" Then
        MsgBox "Error - Cell " & R.Address(0, 0) & " has no value.", vbOKOnly Or vbCritical, "Macro Halt"
        Exit Sub
    End If
    
    Set R = Sheet1.Range("C5")
    If Trim(R.Value) = "" Then
        MsgBox "Error - Cell " & R.Address(0, 0) & " has no value.", vbOKOnly Or vbCritical, "Macro Halt"
        Exit Sub
    End If
    
    Set R = Sheet1.Range("B3")
    If Trim(R.Value) = "" Then
        MsgBox "Error - Cell " & R.Address(0, 0) & " has no value.", vbOKOnly Or vbCritical, "Macro Halt"
        Exit Sub
    End If
    
    FilePath = Application.DefaultFilePath & "\" & Sheet1.Range("B5").Value & "-" & Sheet1.Range("C5").Value & "-" & Sheet1.Range("B3").Value & "-FIRM" & "- COBOT-SYSTEM (LightWELD 2000-XR)"
    Debug.Print FilePath
    
    Select Case MsgBox("File name is:" & vbCrLf _
            & "" & vbCrLf _
            & FilePath & vbCrLf _
            & "" & vbCrLf _
            & "Continue?", vbOKCancel Or vbQuestion, "Constructed File Path")
        Case vbCancel
            Exit Sub
    End Select
    
    
    saveAsFilename = Application.GetSaveAsFilename(FilePath, FileFilter:="PDF File (*.pdf), *.pdf", Title:="Save")
    
    If saveAsFilename = False Then Exit Sub
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,175
Members
452,615
Latest member
bogeys2birdies

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