Excel automation: how to open a blank sheet?

April 03rd, 2009 - 03:24 pm ET by fred | Report spam
Hello,
I am using vbasic and Excel automation.
I do not know how to open the blank sheet.
I tried this:
On Error GoTo nmoExcelApp
Dim moExcelApp As Object
Dim moExcelWBk As Object
Dim moExcelWS As Object
Set moExcelApp = CreateObject("Excel.Application")
If moExcelWS Is Nothing Then
Set moExcelWS =
moExcelApp.Workbooks("blank.csv").Worksheets("blank")
End If
That does not work.
moExcelWS is Nothing
but when I do this:
If moExcelWS Is Nothing Then
Set moExcelWS = moExcelApp.Workbooks.Open(App.Path &
"\blank.csv")
End If
it appears that moExcelWS references to the sheet, but the sheet is not
displayed (visible) on screen.
What to do to have the blank spreadsheet opened and visible?
Thanks,
Fred
email Follow the discussionReplies 13 repliesReplies Make a reply

Similar topics

Replies

#11 Dave Peterson
April 03rd, 2009 - 07:07 pm ET | Report spam
I used to screw things up quite a bit.

I have a shortcut to a .vbs file on my desktop. It consists of this:

dim myXL
On Error Resume Next
Set myXL = GetObject(, "Excel.Application")
If Err.Number = 429 Then
msgbox "Excel is not running"
else
myxl.visible = true
end If
On Error GoTo 0
Set myxl = nothing

=I click on it, close any newly visible excel instances and reclick until I get
that "not running" message.

I didn't try your version in the immediate window, but if that's the immediate
window of Excel's VBE, isn't there a chance that you'll get the same instance
each time.

I've never been able to control separate instances of excel by using getobject.

Bob Butler wrote:

"Dave Peterson" wrote in message
news:
> ps. I bet you have lots of instances of excel running (invisible to you).
>
> Close the visible instance (if there is one)
> And use the taskmanager (alt-ctrl-delete) to delete the running
> excel.exe's in
> the Process tab.
>
> (or reboot your machine to kill all of them.)

In the immediate window:

set x=getobject(,"Excel.Application"):x.visible=true

repeat until it fails; the advantage is that it lets you see what is in each
instance and save as needed




Dave Peterson
Replies Reply to this message
#12 Bob Butler
April 03rd, 2009 - 07:14 pm ET | Report spam
"Dave Peterson" wrote in message
news:
I used to screw things up quite a bit.

I have a shortcut to a .vbs file on my desktop. It consists of this:

dim myXL
On Error Resume Next
Set myXL = GetObject(, "Excel.Application")
If Err.Number = 429 Then
msgbox "Excel is not running"
else
myxl.visible = true
end If
On Error GoTo 0
Set myxl = nothing

=> I click on it, close any newly visible excel instances and reclick until I
get
that "not running" message.

> I didn't try your version in the immediate window, but if that's the
immediate
window of Excel's VBE, isn't there a chance that you'll get the same
instance
each time.

I've never been able to control separate instances of excel by using
getobject.



That's correct; I was reading this in m.p.vb.general.discussion and did not
notice the cross-post to excel.programming. My comment applies to the
immediate window within VB 6, not VBA inside Excel.
Replies Reply to this message
#13 Dave Peterson
April 03rd, 2009 - 07:24 pm ET | Report spam
Ahh.

I didn't notice that it was cross-posted.



Bob Butler wrote:



<<snipped>>

That's correct; I was reading this in m.p.vb.general.discussion and did not
notice the cross-post to excel.programming. My comment applies to the
immediate window within VB 6, not VBA inside Excel.




Dave Peterson
email Follow the discussion Replies Reply to this message
Help Create a new topic Previous pageReplies Make a reply
Search Make your own search