Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have ComboBox and CommandButton on UserForm. I am trying that when
I click CommandButton on UserForm it should copy the Activesheet to ComboBox.Value (which is Workbook.Name) and then protect its macro and close that Workbook with saving all changes in it and then open it again. I been struggling with the code below but for some reason i am getting error. It copies the Activesheet to specified Workbook but not protecting the macro of that sheet and also not opening it after everything is done. Can please someone look my code below and tell that what i am doing wrong. Private Sub CommandButton1_Click() cv = Me.ComboBox1.Value ThisWorkbook.ActiveSheet.Copy after:=Workbooks(cv).Sheets(Sheets.Count) ProtectVBProject Workbooks(cv), "jack" Workbooks(cv).Save Unload UserForm1 Workbooks(cv).Close True Workbooks.Open Filename:=Workbooks(cv) End Sub Sub ProtectVBProject(wb As Workbook, ByVal Password As String) Dim vbProj As Object Set vbProj = wb.VBProject If vbProj.Protection = 1 Then Exit Sub Set Application.VBE.ActiveVBProject = vbProj SendKeys "+{TAB}{RIGHT}%V{+}{TAB}" & Password & "{TAB}" & Password & "~" Application.VBE.CommandBars(1).FindControl(ID:=257 8, recursive:=True).Execute wb.Save End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Value from userform to macro | Excel Programming | |||
Can I use a UserForm Box with a Macro? | Excel Discussion (Misc queries) | |||
Variable from Userform to Macro | Excel Programming | |||
Userform/macro help | Excel Discussion (Misc queries) | |||
Userform Macro | Excel Discussion (Misc queries) |