CrispyAsian
Board Regular
- Joined
- Sep 22, 2017
- Messages
- 64
Hey all,
Having a small issue with my vba code. The code is supposed to throw up a bunch of prompts to confirm saving and then clears out the forms and vba codes and then is supposed to open the new file and then closes the application. However, no matter where I put the Workbooks.open line, it will not open the new workbook. Currently I have it looking like this:
I have no idea where to put the workbooks.open line to make it work or what I'm doing wrong. Anybody have any ideas?
Having a small issue with my vba code. The code is supposed to throw up a bunch of prompts to confirm saving and then clears out the forms and vba codes and then is supposed to open the new file and then closes the application. However, no matter where I put the Workbooks.open line, it will not open the new workbook. Currently I have it looking like this:
Code:
Private Sub ExportButton()Dim answer As Integer
answer = MsgBox("Are you sure you want to export RAP? Document will close without saving after export.", vbYesNo + vbQuestion, "Empty Sheet")
If answer = vbYes Then
Dim i As Integer
If ActiveSheet.ProtectContents = True Then
MsgBox "The Current Workbook or the Worksheets which it contains are protected." & vbLf & "Please resolve these issues and try again."
End If
On Error Resume Next
For i = 1 To 10000
ActiveWorkbook.Sheets(i).Buttons.Delete
Next i
On Error Resume Next
Dim Element As Object
For Each Element In ActiveWorkbook.VBProject.VBComponents
ActiveWorkbook.VBProject.VBComponents.Remove Element
Next
Dim save_as As Variant
Dim file_name As String
Dim ProgramName As String
file_name = ProgramName
' Get the file name.
save_as = Application.GetSaveAsFilename(file_name, _
FileFilter:="Excel Files,*.xlsx,All Files,*.*")
' See if the user canceled.
If save_as = False Then Exit Sub
' Save the file with the new name.
Application.DisplayAlerts = False
If LCase$(Right$(save_as, 4)) <> ".xlsx" Then
file_name = save_as & ".xlsx"
End If
ActiveWorkbook.SaveAs Filename:=save_as, FileFormat:= _
xlOpenXMLWorkbook, CreateBackup:=False
MsgBox ("Document Successfully Exported!")
Application.Quit
Application.ActiveWindow.Close SaveChanges:=False
ActiveWorkbook.Close SaveChanges:=False
Application.Workbooks.Open Filename:=save_as & ".xlsx"
Else
'do nothing
End If
End Sub
I have no idea where to put the workbooks.open line to make it work or what I'm doing wrong. Anybody have any ideas?