A question related to developing a VBA to regulate the format of word file

batman7570

New Member
Joined
Sep 10, 2016
Messages
8
Dear all,

Hi , everyone. i am a beginner to VBA and creating new macro to facilitate my work.
i am doing administration work in my company. Everyday , i need to receive document(in word format) from to whole company and check their format (e.g font size, margin,.....) Then, i come up with two solution , the first one is to create a VBA /macro in excel format then move those content to the word format.The second one is to create a VBA/macro in word so that once i launch the vba, it would change the format of word into what i want.

For solution one, i have already find some code like that:

"Sub Example1()
Dim objWord As Object
Dim objDoc As Object
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Add


Dim i As Integer
Dim strValue As String
For i = 1 To 6
'bring focus to the document created
objDoc.Activate
'read the value from the cell
strValue = Cells(i + 1, 1)
'write the value to the document
objWord.Selection.TypeText Text:=strValue
'move to the next line
objWord.Selection.TypeParagraph
Next i
End Sub"

this code is great , however, i would like to know (1) if i want to create a table in excel then send it to word, how can i write the code?(2)if i want to send a photo from excel to word, what is the code?

For solution 2

(1)i found there is lack of information related to word vba.(2)i would like to know if there is example that someone write a VBA/macro to regulate the format of the word document.

thank you everyone, it is a very good website , i learn a lot from that.:)
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
It seems to me you'd save yourself a lot of work if you created a template for everyone to use, with the required layout & basic content in place and with formatting restricted to defined Styles. It also isn't apparent to me why, if any reformatting is to be done, you'd try to do this with an Excel macro instead of a Word macro.

As for the reformatting task itself, without knowing exactly how the 'problem' documents are formatted and how they should be reformatted, it would be impossible for anyone to write such a macro.

Regarding the table, is there a reason for creating it in Excel instead of in Word?
Regarding the photo, is it actually in an Excel workbook? If so, any code you use would need to know the worksheet name, which Word document you want to add it to and where in that document you want to insert it. For some code to get you started, see: http://www.mrexcel.com/forum/genera...icture-excel-paste-into-word.html#post4646365

PS: The reason you won't find a lot about Word on this site is that, as its name implies, it's primarily an Excel site.
 
Upvote 0

Forum statistics

Threads
1,223,805
Messages
6,174,723
Members
452,578
Latest member
Predaking

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