bradyboyy88
Well-known Member
- Joined
- Feb 25, 2015
- Messages
- 562
Hi,
I was using some code I found online and was wondering if it is possible to open an excel workbook without it ever becoming visible to the screen at all times when it is open. The current code I am using is below. I have tried oXL.visible= False but it still shows up on the screen and application.screenupdating = false also does not seem to help.
Thanks
sub Whatever()
Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim oRng As Excel.Range
Dim ExcelWasNotRunning As Boolean
Dim WorkbookToWorkOn As String
'specify the workbook to work on
WorkbookToWorkOn = "C:\Users\coolguy\testfile.xlsx"
'If Excel is running, get a handle on it; otherwise start a new instance of Excel
On Error Resume Next
Set oXL = GetObject(, "Excel.Application")
If Err Then
ExcelWasNotRunning = True
Set oXL = New Excel.Application
End If
On Error GoTo Err_Handler
'Open the workbook
Set oWB = oXL.Workbooks.Open(FileName:=WorkbookToWorkOn, UpdateLinks:=True)
'Random code I am using is going right here
'Process each of the spreadsheets in the workbook
oXL.DisplayAlerts = False
oWB.Save
oXL.DisplayAlerts = True
If ExcelWasNotRunning Then
oXL.Quit
End If
'Make sure you release object references.
Set oRng = Nothing
Set oSheet = Nothing
Set oWB = Nothing
Set oXL = Nothing
'quit
Exit Sub
Err_Handler:
MsgBox WorkbookToWorkOn & " caused a problem. " & Err.Description, vbCritical, _
"Error: " & Err.Number
If ExcelWasNotRunning Then
oXL.Quit
End If
End Sub
I was using some code I found online and was wondering if it is possible to open an excel workbook without it ever becoming visible to the screen at all times when it is open. The current code I am using is below. I have tried oXL.visible= False but it still shows up on the screen and application.screenupdating = false also does not seem to help.
Thanks
sub Whatever()
Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim oRng As Excel.Range
Dim ExcelWasNotRunning As Boolean
Dim WorkbookToWorkOn As String
'specify the workbook to work on
WorkbookToWorkOn = "C:\Users\coolguy\testfile.xlsx"
'If Excel is running, get a handle on it; otherwise start a new instance of Excel
On Error Resume Next
Set oXL = GetObject(, "Excel.Application")
If Err Then
ExcelWasNotRunning = True
Set oXL = New Excel.Application
End If
On Error GoTo Err_Handler
'Open the workbook
Set oWB = oXL.Workbooks.Open(FileName:=WorkbookToWorkOn, UpdateLinks:=True)
'Random code I am using is going right here
'Process each of the spreadsheets in the workbook
oXL.DisplayAlerts = False
oWB.Save
oXL.DisplayAlerts = True
If ExcelWasNotRunning Then
oXL.Quit
End If
'Make sure you release object references.
Set oRng = Nothing
Set oSheet = Nothing
Set oWB = Nothing
Set oXL = Nothing
'quit
Exit Sub
Err_Handler:
MsgBox WorkbookToWorkOn & " caused a problem. " & Err.Description, vbCritical, _
"Error: " & Err.Number
If ExcelWasNotRunning Then
oXL.Quit
End If
End Sub
Last edited: