LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 557
Default Macro in UserForm

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Value from userform to macro Pawan Excel Programming 2 August 25th 08 03:16 PM
Can I use a UserForm Box with a Macro? Vick Excel Discussion (Misc queries) 3 May 18th 07 01:32 AM
Variable from Userform to Macro Vikesh Jain Excel Programming 2 June 28th 06 06:13 AM
Userform/macro help chip_pyp Excel Discussion (Misc queries) 1 March 29th 06 07:38 PM
Userform Macro Mike Rogers Excel Discussion (Misc queries) 2 March 12th 06 02:16 AM


All times are GMT +1. The time now is 12:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"