Create Excel Workbook etc - Close - in a loop - hyperlink add failure

M

ML

I'm newbie to group - but not in VBA - Access.
I'm generating Excel workbook/sheets etc on the fly and it works! -
except...

I have a loop which

1. copies a template workbook - vba
2 opens it as an Excel object etc
3 assigns hyperlinks to cells

ETC

n. quits the application
n+1 sets application to nothing


This works perfectly for the first loop iteration

next time round it does 1 and 2 but fails on 3

oWrkSh.Cells(i + 6, "F") = Employees(i)
RangeCells = "H" & CStr(i + 6) & ":I" & CStr(i + 6)
oWrkSh.Range(RangeCells).Select

FAILS NEXT STATEMENT even though it was ok for the 1st iteration - workbook

oWrkSh.Hyperlinks.Add Anchor:=Selection, _
Address:="", SubAddress:="'" & Employees(i) & " (Leads)'" & "!A1",
TextToDisplay:="Leads Report"

error says automation error - can't add hyperlink or thereabouts

Any ideas?

TIA Michael
 
M

ML

Thanks for ideas - but solved my own problem. It is an Excel "feature"

Each of the workbooks I was creating had the same filename - different
paths - but eventually xxxx.xls

Even closing the application between workbook creations seemed to leave some
trace of xxxx.xls in "excel memory" - so it failed at really any statement
which referred to a worksheet.

The workaround - bit of a nuisance - Each filename for each new workbook, is
different.

This works .

An aside.

It is the most incredible sight - a "few" lines of code and workbooks and
multi worksheets creating in their multitudes in front of your eyes!


regards,
Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top