Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hide Excel Workbook with VBA code from Access

Status
Not open for further replies.

mmogul

IS-IT--Management
Dec 1, 2003
218
US
I create a number of excel workbooks that contain macros(xlsm) using Access vba code. I am running Office 2007. I want to hide excel during all the processing. The approach shown below worked in Office 2003.

I am using the command xlApp.visible = false (where xlApp is defined as excel.application) to hide Excel and the "copy after" function to make a copy of a "template" worksheet to another. This code works fine as long as there are no ActiveX objects (check boxes, buttons, combo box) on the "source" worksheet.

When the "source" worksheet has one of these ActiveX objects, Excel remains hidden until I use the "copy after" function to make a copy of a worksheet (code sample below). When this command is executed, the Excel workbook becomes visible for a brief time (less than a second) and then it is hidden again. I need to avoid this since it interrupts the user during this processing.

Anyone have any thoughts on how to handle this? Can you replicate this behavior? Here is the code.

Code:
Private Sub cmdTest_Click()
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim sDestinationFile As String

sDestinationFile = "c:\rad\test.xlsm"
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = False
Set xlWB = xlApp.Workbooks.Open(sDestinationFile)
[COLOR=red]
xlWB.Sheets("Facility").Copy After:=xlWB.Sheets("Facility")
[/color]

xlWB.ActiveSheet.Name = "newName"

xlWB.Save    
xlWB.Close    
xlApp.Quit        
Set xlWB = Nothing    
Set xlApp = Nothing        
End Sub

(This is also posted in the Access Modules (VBA Coding) forum)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top