View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
MikeZz MikeZz is offline
external usenet poster
 
Posts: 152
Default Hide VBProject while copying Forms & Modules to another workbo

Hi Peter,
This seems to do what it's supposed to.
Is there a way to check if VBA is open at the beginning of my code and then
only close it if it wasn't open at the start?

Thanks again for the support,
MikeZz

"Peter T" wrote:

I don't think there is any way to prevent the VBE from opening when you do
CreateEventProc

There are various ways to close it when done, following is probably the
simplest

Dim cbc As CommandBarControl
Set cbc = Application.VBE.CommandBars.FindControl(ID:=752)
cbc.Execute

Regards,
Peter T

"MikeZz" wrote in message
...
Hi,
I have an automated application that modifies a number of workbooks by
adding some forms and modules to each one, then saves and closes them.

During this process, I use Application.visible = false to hide all the
opening/closing workbooks so that the user can do other work without focus
jumping to Excel.

The problem is that for some reason, the Visual Basic window opens at some
point and never closes. This defeats the purpose of making the
application
visible and I don't know why it's opening the window. It also confuses
the
user running the application because she doesn't know anything about
excel.

Any ideas on what command is actually making VBA visible?
Any ideas on how to make it invisible?

This one's a real bear because if I put a "Stop" or Pause in VBA, VBA
automatically becomes visible so there's no way for me to see what's
tripping
the visiblity property.

Thanks,
MikeZz


Here is the basic routine that copies over the forms and modules:
Public Sub SendForms()
errMaster = "SendForms: Sending Macros"

srcWB.VBProject.VBComponents("frmNotFound").Export Filename:=sStr
destWb.VBProject.VBComponents.Import Filename:=sStr
srcWB.VBProject.VBComponents("StartupForm").Export Filename:=sStr
destWb.VBProject.VBComponents.Import Filename:=sStr
srcWB.VBProject.VBComponents("ExportCode").Export Filename:=sStr
destWb.VBProject.VBComponents.Import Filename:=sStr
Kill sStr

Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Dim LineNum As Long
Const DQUOTE = """" ' one " character

Set VBProj = ActiveWorkbook.VBProject
Set VBComp = VBProj.VBComponents("ThisWorkbook")
Set CodeMod = VBComp.CodeModule

With CodeMod
LineNum = .CreateEventProc("Open", "Workbook")
LineNum = LineNum + 1
.InsertLines LineNum, " ThisWorkbook.Sheets(" & DQUOTE &
"VeryHidden" & DQUOTE & ").Visible = xlVeryHidden"
LineNum = LineNum + 1
.InsertLines LineNum, " StartupForm.Show"
End With
End Sub