Platforms: Win Vista, Win 7, Mac OS X 10
Excel: Version 2007
Description:
Hello!
I'm haveing this problem with a ActiveX commandbutton i added to worksheet1. Infact i got this commandbutton which copies sheet 1, makes a new (xlm/xlms & so on) file (based on the active worksheet) and pastes the values in the new file .
Now my problem is that sheet 1 has also a Activex button which activates the program (userform) i made. I only want the data from the fields, but not the Activex commandbutton i made.
So heres the full code:
What i have done to make it work like that, but failed:
I've added function to select only the cells which are filled.
Anyway im open to suggestions.
Thank you in advance
Excel: Version 2007
Description:
Hello!
I'm haveing this problem with a ActiveX commandbutton i added to worksheet1. Infact i got this commandbutton which copies sheet 1, makes a new (xlm/xlms & so on) file (based on the active worksheet) and pastes the values in the new file .
Now my problem is that sheet 1 has also a Activex button which activates the program (userform) i made. I only want the data from the fields, but not the Activex commandbutton i made.
So heres the full code:
Code:
Private Sub SaveWork_Click()
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim LastCol As Long
Dim LastRow As Long
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set Sourcewb = ActiveWorkbook
With Worksheets("Sheet1")
LastCol = ActiveSheet.Range("a1").End(xlToRight).Column
LastRow = ActiveSheet.Cells(65536, LastCol).End(xlUp).Row
ActiveSheet.Range("a1", ActiveSheet.Cells(LastRow, LastCol)).Select
ActiveSheet.Copy
End With
Set Destwb = ActiveWorkbook
With Destwb
If Val(Application.Version) < 12 Then
FileExtStr = ".xls": FileFormatNum = -4143
Else
If Sourcewb.name = .name Then
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
MsgBox "Your answer is NO in the security dialog"
Exit Sub
Else
Select Case Sourcewb.FileFormat
Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
Case 52:
If .HasVBProject Then
FileExtStr = ".xlsm": FileFormatNum = 52
Else
FileExtStr = ".xlsx": FileFormatNum = 51
End If
Case 56: FileExtStr = ".xls": FileFormatNum = 56
Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
End Select
End If
End If
End With
On Error GoTo FileWasNotSaved
With Worksheets("Sheet1")
LastCol = ActiveSheet.Range("a1").End(xlToRight).Column
LastRow = ActiveSheet.Cells(65536, LastCol).End(xlUp).Row
ActiveSheet.Range("a1", ActiveSheet.Cells(LastRow, LastCol)).Select
ActiveSheet.Cells.Copy
.Cells.PasteSpecial xlPasteValues
.Cells(1).Select
End With
Application.CutCopyMode = False
TempFilePath = Application.DefaultFilePath & "\AR\"
If CheckBox1.Value = True Then
TempFileName = Format(Now, "dd-mm-yyyy") & " TM"
Else
TempFileName = Format(Now, "dd-mm-yyyy")
End If
With Destwb
.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
.Close SaveChanges:=False
End With
MsgBox "You can find the new file in " & TempFilePath
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
FileWasNotSaved:
If Err.Number = 1004 Then
HelpBox.Caption = "File was not saved. Either you did not want to overwrite an existing file or you do not have the folder \AR\ in your Documents folder. Example: C:\Users\PC-1\Documents'\AR\'"
Else
HelpBox.Caption = "File was saved Successfully"
End If
End Sub
What i have done to make it work like that, but failed:
I've added function to select only the cells which are filled.
Code:
LastCol = ActiveSheet.Range("a1").End(xlToRight).Column
LastRow = ActiveSheet.Cells(65536, LastCol).End(xlUp).Row
ActiveSheet.Range("a1", ActiveSheet.Cells(LastRow, LastCol)).Select
Anyway im open to suggestions.
Thank you in advance