How to: Remove a ActiveX Commandbutton while saveing

cdragone

New Member
Joined
Jul 8, 2011
Messages
8
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:
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
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,224,503
Messages
6,179,134
Members
452,890
Latest member
Nikhil Ramesh

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