View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
CST[_2_] CST[_2_] is offline
external usenet poster
 
Posts: 14
Default Strange Problem: Opening Excel using VB appends 1

I am opening an Excel file via VB. The file has vba code/macros,
which get fired off on Workbook Open. If there is an error while
opening the document, I have code that kills the particular Process ID
for the respective Excel file. I actually use the FindWindow API
function to determine the window handle, in turn killing the
corresponding id. My issue is that occassionally a 1 gets appened to
the file name (e.g., Bad1.xls) and I have no clue why. Is this
because a copy is created in memory somewhere? As you can see, I need
the exact window name to get the corresponding processid. Since I
don't understand why the 1 gets appended, I can't always assume that
it will append a 1.

Private Sub Command1_Click()
Dim oXLS As New Excel.Application
Dim oWK As New Excel.Workbook

oXLS.Visible = True
Set oWK = Workbooks.Open("C:\Temp\Bad.xls")
Set oXLS = Nothing
Set oWK = Nothing
End Sub

This behavior actually occurs when I do XWrk.PrintOut
ActivePrinter:="Acrobat Distiller" too. Is there anyway to avoid
this? Why is this happening?

TIA
Note: I posted this in VB group and am posting it here also