VBA Convert Frame to TextBox WORD 2010

Fin Fang Foom

Well-known Member
Joined
Mar 20, 2005
Messages
598
Hi,

I have a Word document that has alot of frames. I got this code below that will convert the Frame to TexBox. BUT it will just do one Frame.

How to modify the code that it will loop through the whole document and covert ALL frames to TexBox.


https://social.msdn.microsoft.com/F.../vba-to-convert-frame-to-textbox?forum=isvvba



Sub Convert_Frame_to_TextBox()


Dim frame As Word.frame
Set frame = ActiveDocument.Frames(1)
Dim CopyRange As Word.Range
Set CopyRange = frame.Range.Duplicate

With frame.Range
.Select
.Cut
.Select

End With
Dim CursorX, CursorY, FrameWidth, FrameHeight
CursorX = Selection.Information(wdHorizontalPositionRelativeToPage)
CursorY = Selection.Information(wdVerticalPositionRelativeToPage)
FrameWidth = ActiveDocument.Frames(1).Width
FrameHeight = ActiveDocument.Frames(1).Height
Dim txtbox As Word.Shape
Set txtbox = ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, CursorX, CursorY, FrameWidth, FrameHeight)



txtbox.Select
Selection.Range.Paste
txtbox.Select
Selection.Cut
frame.Select
Selection.Delete
Selection.Paste


End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
From within Word, try...

<font face=Courier New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN><br><br><SPAN style="color:#00007F">Sub</SPAN> Convert_Frames_to_TextBoxes()<br><br>    <SPAN style="color:#00007F">Dim</SPAN> oFrame          <SPAN style="color:#00007F">As</SPAN> Frame<br>    <SPAN style="color:#00007F">Dim</SPAN> oTextBox        <SPAN style="color:#00007F">As</SPAN> Shape<br>    <SPAN style="color:#00007F">Dim</SPAN> CursorX         <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> CursorY         <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> FrameWidth      <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> FrameHeight     <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN><br>    <br>    <SPAN style="color:#00007F">If</SPAN> ActiveDocument.Frames.Count = 0 <SPAN style="color:#00007F">Then</SPAN><br>        MsgBox "No frames found!"<br>        <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <br>    <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> oFrame <SPAN style="color:#00007F">In</SPAN> ActiveDocument.Frames<br>        CursorX = oFrame.Range.Information(wdHorizontalPositionRelativeToPage)<br>        CursorY = oFrame.Range.Information(wdVerticalPositionRelativeToPage)<br>        FrameWidth = oFrame.Width<br>        FrameHeight = oFrame.Height<br>        <SPAN style="color:#00007F">Set</SPAN> oTextBox = ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, _<br>            CursorX, CursorY, FrameWidth, FrameHeight)<br>        oFrame.Range.Cut<br>        oTextBox.TextFrame.TextRange.Paste<br>        oFrame.Delete<br>    <SPAN style="color:#00007F">Next</SPAN> oFrame<br>    <br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,220,414
Messages
6,153,759
Members
451,166
Latest member
Willie77

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