Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Setting range object--Type mismatch if template not used

Hi All;

I'm a bit baffled. I have the following code that works fine as long
as I use a template to create the workbook:

Set objXL = New Excel.Application
With objXL
.Visible = True
Set objWkb = objXL.Workbooks.Add
("\\SomeServer\Reporting\test.xlt")

Set objSht = objWkb.Worksheets.Add
objSht.Name = conSHT_NAME

End With
objWkb.SaveAs (pstrWorkbookLoc)
Set rngCurr = Nothing
lngRtnErr = lngCreateTable(objSht)
....(skip into lngCreateTable..see below

Public Function lngCreateTable(objSht As Excel.Worksheet) As Long

Dim rngCurr As Range

Set rngCurr = objSht.Range("A3")


The line above causes a Type Mismatch error unless I use a Template
when creating the Workbook. Can anyone tell me why?

Thanks in advance
Cheryl

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Setting range object--Type mismatch if template not used

Cheryl,
Your code worked for me from Excel.
If you are automating Excel from Word or elsewhere then
the rngCurr declaration is ambivalent.
Word has a Range object as well as Excel.

replace...
Dim rngCurr as Range
with
Dim rngCurr as Excel.Range
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(free Excel add-ins plus Special Sort)



wrote in message
Hi All;
I'm a bit baffled. I have the following code that works fine as long
as I use a template to create the workbook:

Set objXL = New Excel.Application
With objXL
.Visible = True
Set objWkb = objXL.Workbooks.Add
("\\SomeServer\Reporting\test.xlt")

Set objSht = objWkb.Worksheets.Add
objSht.Name = conSHT_NAME

End With
objWkb.SaveAs (pstrWorkbookLoc)
Set rngCurr = Nothing
lngRtnErr = lngCreateTable(objSht)
....(skip into lngCreateTable..see below

Public Function lngCreateTable(objSht As Excel.Worksheet) As Long
Dim rngCurr As Range
Set rngCurr = objSht.Range("A3")
The line above causes a Type Mismatch error unless I use a Template
when creating the Workbook. Can anyone tell me why?
Thanks in advance
Cheryl

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Setting range object--Type mismatch if template not used

Jim;

Thanks--declaring the range as an Excel.Range object did the trick. I
had forgotten to mention that I was automating this from Access.

regards
Cheryl

Jim Cone wrote:
Cheryl,
Your code worked for me from Excel.
If you are automating Excel from Word or elsewhere then
the rngCurr declaration is ambivalent.
Word has a Range object as well as Excel.

replace...
Dim rngCurr as Range
with
Dim rngCurr as Excel.Range
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(free Excel add-ins plus Special Sort)



wrote in message
Hi All;
I'm a bit baffled. I have the following code that works fine as long
as I use a template to create the workbook:

Set objXL = New Excel.Application
With objXL
.Visible = True
Set objWkb = objXL.Workbooks.Add
("\\SomeServer\Reporting\test.xlt")

Set objSht = objWkb.Worksheets.Add
objSht.Name = conSHT_NAME

End With
objWkb.SaveAs (pstrWorkbookLoc)
Set rngCurr = Nothing
lngRtnErr = lngCreateTable(objSht)
...(skip into lngCreateTable..see below

Public Function lngCreateTable(objSht As Excel.Worksheet) As Long
Dim rngCurr As Range
Set rngCurr = objSht.Range("A3")
The line above causes a Type Mismatch error unless I use a Template
when creating the Workbook. Can anyone tell me why?
Thanks in advance
Cheryl


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Type mismatch using rnge as Range with Type 8 Input Box STEVE BELL Excel Programming 11 December 3rd 05 05:02 AM
Type mismatch on range name davegb Excel Programming 2 June 8th 05 06:15 PM
Type mismatch in VBA LinEst function if range too large RyanVM[_16_] Excel Programming 4 August 10th 04 02:47 AM
setting ctl to array of checkboxes yields type mismatch error. tritan Excel Programming 0 July 11th 03 09:22 PM
setting ctl to array of checkboxes yields type mismatch error. Tritan Excel Programming 0 July 11th 03 07:50 PM


All times are GMT +1. The time now is 11:38 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"