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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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,214,591
Messages
6,120,431
Members
448,961
Latest member
nzskater

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