Ask Question Forum:
Model Library:2025-02-08 Updated:A.I. model is online for auto reply question page
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by murbro
at 2024-08-30 00:00:53
Point:500 Replies:4 POST_ID:829204USER_ID:11939
Topic:
Microsoft Excel Spreadsheet Software;;
Hi
What Excel VBA code would I use to check if there is a workbook open and if not add a new blank one.
Thanks
What Excel VBA code would I use to check if there is a workbook open and if not add a new blank one.
Thanks
Author: murbro replied at 2024-09-01 10:53:03
Thank for the help
Assisted Solution
Expert: Rory Archibald replied at 2024-09-01 06:03:02
166 points EXCELLENT
Not really - you can automate a different instance of Excel from Excel after all. Also, it depends if you regard an add-in as a workbook.
A simple Application.Workbooks.Count statement will tell you how many workbooks are open, including add-ins and hidden workbooks like Personal Macro workbooks.
A simple Application.Workbooks.Count statement will tell you how many workbooks are open, including add-ins and hidden workbooks like Personal Macro workbooks.
Assisted Solution
Expert: Qlemo replied at 2024-08-31 14:55:57
167 points EXCELLENT
That's correct - you cannot use VBA code without a workbook. You can, however, run Automation code (e.g. from VB, PowerShell, VBS, ...) outside of Excel. But the way the question is asked, that is out of scope.
Accepted Solution
Expert: rwniceing replied at 2024-08-30 00:37:46
167 points EXCELLENT
Probably, You have to at least open one workbook to do VBA coding. So it must have at least one workbook open on Excel. Please write more about your question and need
So I guess you check whether some xls file workbook open or not, If not, create a blank workbook.
Is it what you want ? if so, please read the following code
So I guess you check whether some xls file workbook open or not, If not, create a blank workbook.
Is it what you want ? if so, please read the following code
Sub check_open() Dim oldworkbook As String Dim newworkbook As Stringnewworkbook="testing.xls" oldworkbook = "checkfile.xls" 'Debug.Print InStr(ActiveWorkbook.name, oldworkbook) If InStr(ActiveWorkbook.name, oldworkbook) > 0 Then Debug.Print ActiveWorkbook.name Else Workbooks.Add 'Workbooks.Add.SaveAs Filename:="c: emp" & newworkbook End If End Sub 1:2:3:4:5:6:7:8:9:10:11:12:13: