very strange

Alisa

Board Regular
Joined
Jan 28, 2005
Messages
97
I have never had this problem before, has anyone else?

This code adds a text box to a certain sheet and writes text in it:

Sheets(1).Select
ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 0, _
0, 320#, 180#).Select
With Selection
.Characters.Text = "No " & constituent & " Data" 'ERROR ON THIS LINE
.HorizontalAlignment = xlCenter
End With


This is the error I get:
run-time error 438, object doesn't support this variable or method
When the error occurs, the text box is placed correctly and selected.

The strange thing is, the code works fine most of the time. I can't find any rhyme or reason as to why it works sometimes and not others. Any ideas?
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Selecting stuff is risky sometimes... try this:

<font face=Courier New>
<SPAN style="color:#00007F">Sub</SPAN> T()
   <SPAN style="color:#00007F">Dim</SPAN> Shp <SPAN style="color:#00007F">As</SPAN> Shape
  
   <SPAN style="color:#00007F">Dim</SPAN> constituent <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
   constituent = "something"
  
   <SPAN style="color:#00007F">Set</SPAN> Shp = Sheets(1).Shapes.AddTextbox(msoTextOrientationHorizontal, 0, 0, 320#, 180#)
  
   <SPAN style="color:#00007F">With</SPAN> Shp.TextFrame
      .Characters.Text = "No " & constituent & " Data"  <SPAN style="color:#007F00">'ERROR ON THIS LINE</SPAN>
      .HorizontalAlignment = xlCenter
   <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>
 
Upvote 0
Yes it works! Thank you so much, you have no idea how many hours I have spent trying to figure this out.

with tremendous gratitude, Alisa
 
Upvote 0

Forum statistics

Threads
1,207,195
Messages
6,077,010
Members
446,250
Latest member
Dontcomehereoften

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top