Help with variable

HebertsYES

New Member
Joined
Oct 4, 2014
Messages
15
How can I make this bit of code work?

Dim Top1 As Range
Dim Top2 As Range
Set Top2 = ActiveSheet.Shapes.TextBoxTop2.Range
Set Top1 = ActiveSheet.Shapes.Range("TextBoxTop1")

With Top1
.TextFrame.Characters.Text = Verse
End With
With Top2
.TextFrame.Characters.Text = Ref
End With

Thanks
Here is all of the code
Private Sub ButtonClose_Click()
UFCreateCards.Hide
ActiveWorkbook.Save
ActiveWorkbook.Close
End Sub


Private Sub ButtonPrint_Click()
Dim Top1 As Range
Dim Top2 As Range
Set Top2 = ActiveSheet.Shapes.Range("TextBoxTop2")
Set Top1 = ActiveSheet.Shapes.Range("TextBoxTop1")


Verse = UFCreateCards.TextVerse.Value
Ref = UFCreateCards.TextRef.Value


'Clear all Text boxes
'Sheet1.Shapes.Range("TextBoxTop1").TextFrame.Characters.Delete
'Sheet1.Shapes.Range("TextBoxTop2").TextFrame.Characters.Delete

' Set Sheets textbox values to Sheets Textbox values
With Top1
.TextFrame.Characters.Text = Verse
End With
With Top2
.TextFrame.Characters.Text = Ref
End With


'Changes font Size


Sheet1.Shapes.Range(Array("TextBoxTop2")).Select

With Selection.ShapeRange.TextFrame2.TextRange
.Font.Size = 20
.ParagraphFormat.Alignment = _
msoAlignCenter
End With
Sheet1.Shapes.Range(Array("TextBoxTop1")).Select


Selection.ShapeRange.TextFrame2.TextRange.Font.Size = 16
'Print
'Application.ActivePrinter = "HP Photosmart C4600 series"

ActiveWindow.SelectedSheets.PrintOut Copies:=TextPrintNumber.Value, Collate:=True, _
IgnorePrintAreas:=False

ActiveWorkbook.Save











End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Try something like this...

Code:
[COLOR=darkblue]Sub[/COLOR] ButtonPrint_Click()
    
    [COLOR=green]' Set Sheets textbox values to Sheets Textbox values[/COLOR]
    [COLOR=darkblue]With[/COLOR] ActiveSheet.Shapes("TextBoxTop1")
        .TextFrame.Characters.Text = UFCreateCards.TextVerse.Value
        .TextFrame.Characters.Font.Size = 16
        .TextFrame.HorizontalAlignment = xlHAlignCenter
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]
    
    [COLOR=darkblue]With[/COLOR] ActiveSheet.Shapes("TextBoxTop2")
        .TextFrame.Characters.Text = UFCreateCards.TextRef.Value
        .TextFrame.Characters.Font.Size = 20
        .TextFrame.HorizontalAlignment = xlHAlignCenter
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]
    
    ActiveWindow.SelectedSheets.PrintOut Copies:=TextPrintNumber.Value, Collate:=True, _
        IgnorePrintAreas:=[COLOR=darkblue]False[/COLOR]
    
    ActiveWorkbook.Save
    
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]

Please make use of CODE tags (see my signature block below). It makes reading your code in the forum much easier.
 
Upvote 0
Thanks! I guess my question is How can I Set this code to a variable:
Code:
 ActiveSheet.Shapes("TextBoxTop1")
 
Upvote 0
You're welcome.

No (if I understand what you're asking). That's an object's property. The text could be written to or from a string variable, but not set as a variable.
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,547
Members
449,089
Latest member
davidcom

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