Hi there,
I've an Excel Workbook (SAP Upload File) that has an Export Button, on clicking it I want to ave a copy of that active worksheet to the user's desktop. After running the below code it is showing a compile error 'Expected End with'.
If someone could check this out would be awesome. Please let me know if you need any further information.
Thanks!
____________________________________________________________________________
Sub Export()
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim sh As Worksheet
Dim DateString As String
Dim FolderName As String
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
'Save file to users desktop
Dim TempFilePath As String
Dim TempFileName As String
Set Destwb = ActiveWorkbook
TempFilePath = "C:\Users\" & Environ$("Username") & "\Desktop\"
TempFileName = fName & "_allocation"
FileExtStr = ".txt": FileFormatNum = -4158
With Destwb
.SaveAs TempFilePath & TempFileName & FileExtStr, _
FileFormat:=FileFormatNum
On Error Resume Next
On Error GoTo 0
.Close savechanges:=False
End With
'Change all cells in the worksheet to values if you want
If Destwb.Sheets(1).ProtectContents = False Then
With Destwb.Sheets(1).UsedRange
.Cells.Copy
.Cells.PasteSpecial xlPasteValues
.Cells(1).Select
End With
Application.CutCopyMode = False
'Save the new workbook and close it
With Destwb
fName = Range("G1").Value
ActiveWorkbook.SaveAs Filename:="C:\Users\" & Environ$("Username") & "\Desktop\" & fName & "_Advanced_Ladder_upload" & "_R" & "_" & SectionYear & SectionMonth & SectionDay & SectionHour & SectionMinute & SectionSecond & "", _
FileFormat:=xlText, CreateBackup:=False
MsgBox "You can find the files in " & FolderName
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = xlCalculationAutomatic
End With
End Sub
I've an Excel Workbook (SAP Upload File) that has an Export Button, on clicking it I want to ave a copy of that active worksheet to the user's desktop. After running the below code it is showing a compile error 'Expected End with'.
If someone could check this out would be awesome. Please let me know if you need any further information.
Thanks!
____________________________________________________________________________
Sub Export()
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim sh As Worksheet
Dim DateString As String
Dim FolderName As String
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
'Save file to users desktop
Dim TempFilePath As String
Dim TempFileName As String
Set Destwb = ActiveWorkbook
TempFilePath = "C:\Users\" & Environ$("Username") & "\Desktop\"
TempFileName = fName & "_allocation"
FileExtStr = ".txt": FileFormatNum = -4158
With Destwb
.SaveAs TempFilePath & TempFileName & FileExtStr, _
FileFormat:=FileFormatNum
On Error Resume Next
On Error GoTo 0
.Close savechanges:=False
End With
'Change all cells in the worksheet to values if you want
If Destwb.Sheets(1).ProtectContents = False Then
With Destwb.Sheets(1).UsedRange
.Cells.Copy
.Cells.PasteSpecial xlPasteValues
.Cells(1).Select
End With
Application.CutCopyMode = False
'Save the new workbook and close it
With Destwb
fName = Range("G1").Value
ActiveWorkbook.SaveAs Filename:="C:\Users\" & Environ$("Username") & "\Desktop\" & fName & "_Advanced_Ladder_upload" & "_R" & "_" & SectionYear & SectionMonth & SectionDay & SectionHour & SectionMinute & SectionSecond & "", _
FileFormat:=xlText, CreateBackup:=False
MsgBox "You can find the files in " & FolderName
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = xlCalculationAutomatic
End With
End Sub