PDA

View Full Version : can't call subs automatically



tommy1234
10-07-2009, 11:39 PM
Hello
i wrote 3 subs :
the first unprotect vbaproject ("UnprotectProject_v2")
the second delete the password of the vba project("Delete_Password_v2")
the third save everything in a new name ("save_new1")
i create a fourth sub that just call to the 3 subs written above ("test_v1")
the problem is that a can't run everything automatically.
does someone know the reason, and can help me to solve the problem ?

thanks



Sub UnprotectProject_v2()
Application.ScreenUpdating = False
'open vbe project
Application.SendKeys "%{F11}", True
'ActiveWindow.Activate
With Application
'Activate Project Explorer window
.SendKeys "^r", True
.SendKeys "{TAB}", True
.SendKeys "{TAB}", True
.SendKeys "{TAB}", True
.SendKeys "~", True
'my password
.SendKeys "avi12", True
'Enter again
.SendKeys "~", True
End With
'close vba project
Application.SendKeys "%f", True
Application.SendKeys "c", True
End Sub

Sub Delete_Password_v2()
Application.ScreenUpdating = False
'open vbe project
Application.SendKeys "%{F11}", True
With Application
'Activate Project Explorer window
.SendKeys "^r", True
.SendKeys "{TAB}", True
.SendKeys "{TAB}", True
.SendKeys "{TAB}", True
.SendKeys "%T", True
.SendKeys "E", True
.SendKeys "^{TAB}", True
.SendKeys "V", True
.SendKeys "{TAB}", True
.SendKeys "{BS}", True
.SendKeys "{TAB}", True
.SendKeys "{BS}", True
.SendKeys "{TAB}", True
.SendKeys "~", True
End With
'close vba Window
Application.SendKeys "%f", True
Application.SendKeys "c", True
End Sub

Sub save_new1()
Dim Msg, Style, Title, Ctxt, Response, MyString
Dim currentdate
'currentdate = FormatDateTime(Date, vbGeneralDate)
Msg = "The filename you are about to save is :" & Chr(13) & (Worksheets("data").Range("C3") & Chr(13) _
& Worksheets("data").Range("c4"))
Style = vbYesNo + vbDefaultButton2
Title = "Information"
Ctxt = 1000 ' Define topic
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then
Application.Dialogs(xlDialogSaveAs).Show (Worksheets("data").Range("C3") & "_" & Worksheets("data").Range("C4"))
Else ' User chose No.
MsgBox "You Decided Not To Save"
End If
End Sub

Sub test_v1()
Call UnprotectProject_v2
Call Delete_Password_v2
Call save_new1
End Sub

georgiboy
10-08-2009, 10:46 AM
Why not run each sub from the previous sub like this...
Sub UnprotectProject_v2()
Application.ScreenUpdating = False
'open vbe project
Application.SendKeys "%{F11}", True
'ActiveWindow.Activate
With Application
'Activate Project Explorer window
.SendKeys "^r", True
.SendKeys "{TAB}", True
.SendKeys "{TAB}", True
.SendKeys "{TAB}", True
.SendKeys "~", True
'my password
.SendKeys "avi12", True
'Enter again
.SendKeys "~", True
End With
'close vba project
Application.SendKeys "%f", True
Application.SendKeys "c", True
Call Delete_Password_v2
End Sub

Sub Delete_Password_v2()
Application.ScreenUpdating = False
'open vbe project
Application.SendKeys "%{F11}", True
With Application
'Activate Project Explorer window
.SendKeys "^r", True
.SendKeys "{TAB}", True
.SendKeys "{TAB}", True
.SendKeys "{TAB}", True
.SendKeys "%T", True
.SendKeys "E", True
.SendKeys "^{TAB}", True
.SendKeys "V", True
.SendKeys "{TAB}", True
.SendKeys "{BS}", True
.SendKeys "{TAB}", True
.SendKeys "{BS}", True
.SendKeys "{TAB}", True
.SendKeys "~", True
End With
'close vba Window
Application.SendKeys "%f", True
Application.SendKeys "c", True
Call save_new1
End Sub

Sub save_new1()
Dim Msg, Style, Title, Ctxt, Response, MyString
Dim currentdate
'currentdate = FormatDateTime(Date, vbGeneralDate)
Msg = "The filename you are about to save is :" & Chr(13) & (Worksheets("data").Range("C3") & Chr(13) _
& Worksheets("data").Range("c4"))
Style = vbYesNo + vbDefaultButton2
Title = "Information"
Ctxt = 1000 ' Define topic
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then
Application.Dialogs(xlDialogSaveAs).Show (Worksheets("data").Range("C3") & "_" & Worksheets("data").Range("C4"))
Else ' User chose No.
MsgBox "You Decided Not To Save"
End If
End Sub


Hope this helps

tommy1234
10-08-2009, 02:23 PM
i can't run another sub after the use of .sendkey no matter where the sub is located - inside procedure or outside procedure.