adapt a VBA code for word to make it run in excel

kuitogu67

New Member
Joined
Aug 18, 2020
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
Hello, I have a macro that copies all the textboxes from excel into a word file.

After that, I would like to change the style of the textboxes internal text in word to "no spacing".

This is the code I am using. If I run it from word it works, but from excel it doesn't.

Any idea why?

VBA Code:
    Sub SetTextBoxStyle()
      Dim objTextBox As Shape
      Dim objDoc As Document
      Set objDoc = WordApp.ActiveDocument
      For Each objTextBox In objDoc.Shapes
      If objTextBox.TextFrame.HasText Then
      objTextBox.TextFrame.TextRange.ParagraphFormat.LineSpacingRule = wdLineSpaceSingle
      objTextBox.TextFrame.TextRange.ParagraphFormat.SpaceAfter = 0
      End If
      Next objTextBox
    End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Welcome to the forum.

Please take a minute to read the forum rules on cross-posting, and then add the relevant links here to your posts in other forums on this topic. Thanks. :)
 
Upvote 0

Forum statistics

Threads
1,215,339
Messages
6,124,363
Members
449,155
Latest member
ravioli44

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