Hi
When writing a VBA procedure, somehow I can't refer to workbooks by their
name anymore.
P.e. in Watch window
Workbooks(quot;ReadRepquot;)
returns an error quot;Subscript out of rangequot;. At same time p.e.
Workbooks(1)
works.
So I have to use p.e.
Workbooks(1).Sheets(quot;Raportquot;).Range(quot;B6:Hquot; amp; [RowCount]
5).ClearContents
instead of
Workbooks(quot;ReadRepquot;).Sheets(quot;Raportquot;).Range(quot;B6:Hquot; amp; [RowCount]
5).ClearContents
, but I can never be sure, that there were no workbooks opened before.
Another odd thing: I needed in 2 columns to replace all commas with periods.
The code
ActiveWorkbook.Range(quot;G:Hquot;)..Replace What:=quot;,quot;, Replacement:=quot;.quot;,
LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
did return an error. I tried
ActiveWorkbook.Range(quot;G:Hquot;).Select
Selection.Replace What:=quot;,quot;, Replacement:=quot;.quot;, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
, and
ActiveWorkbook.Columns(quot;G:Hquot;).Select
Selection.Replace What:=quot;,quot;, Replacement:=quot;.quot;, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
, and again did get an error - on Select command. The error message was
quot;Run-time error '438': Object doesn't support this property or methodquot;Has someone a clue, what is going on?
Thank in advance!
--
Arvi Laanemets
( My real mail address: arvi.laanemetslt;atgt;tarkon.ee )
It sounds like you have the code in a different spreadsheet to the one
on which you want to operate - but I would have thought you had noticed
that.
You could check using activeworkbook.name and thisworkbook.name but
again I would have thought you would have noticed this.
Regards--
tony h
------------------------------------------------------------------------
tony h's Profile: www.excelforum.com/member.php...oamp;userid=21074
View this thread: www.excelforum.com/showthread...hreadid=507142Hi
The code was in active workbook, but your tip did gave me a start anyway. I
had to refer to workbook usinf it's name with extension. I.e.
Workbooks(quot;ReadRep.xlsquot;) instead Workbooks(quot;ReadRepquot;), etc. Strange, from MS
Help :
Workbooks Property Example
This example activates the workbook Book1.xls.
Workbooks(quot;BOOK1quot;).Activate
And with replace was my fault too - I did forget to determine the worksheet
:-((--
Arvi Laanemets
( My real mail address: arvi.laanemetslt;atgt;tarkon.ee )
quot;tony hquot; gt; wrote in
message ...
gt;
gt; It sounds like you have the code in a different spreadsheet to the one
gt; on which you want to operate - but I would have thought you had noticed
gt; that.
gt;
gt; You could check using activeworkbook.name and thisworkbook.name but
gt; again I would have thought you would have noticed this.
gt;
gt; Regards
gt;
gt;
gt; --
gt; tony h
gt; ------------------------------------------------------------------------
gt; tony h's Profile:
gt; www.excelforum.com/member.php...oamp;userid=21074
gt; View this thread: www.excelforum.com/showthread...hreadid=507142
gt;
Glad to be of help. You may notice that a new workbook does not have a
.xls extension it is only once it has been saved.--
tony h
------------------------------------------------------------------------
tony h's Profile: www.excelforum.com/member.php...oamp;userid=21074
View this thread: www.excelforum.com/showthread...hreadid=507142
- Apr 13 Sun 2008 20:43
Excel2000: Weird behaviour in VBA
close
全站熱搜
留言列表
發表留言