Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-28-2011, 07:45 PM
OfficeHelpSG OfficeHelpSG is offline Macro - Microsoft Word 2010 Windows XP Macro - Microsoft Word 2010 Office 2010 32bit
Novice
Macro - Microsoft Word 2010
 
Join Date: Aug 2011
Posts: 1
OfficeHelpSG is on a distinguished road
Default Macro - Microsoft Word 2010

Hello,
I'm using Microsoft Word 2010, and every Macro I try and create for a letterhead, does not work. The formatting of my text is not shown when I run the macro! The size changes, and the bold does not apply. The weird thing is everytime I run the macro in the same document or in a different document, it doesnt ever show the same.
I'd like a letterhead macro to turn out like this (The top line should be in 16, the second line in 10 and the last two lines in size 12):

Turner and Sons Accouting Pty Ltd
ABN: 22 333 111 555
22 Kings St, Sydney 2000
Phone: (02) 9675 4444 Fax: (02) 9675 4443


The code for the text is:
Sub Letterhead()
'


' Letterhead Macro
'
'
Selection.TypeText Text:="Turner and Sons Accounting Pty Ltd"
Selection.TypeParagraph
Selection.Font.Bold = wdToggle
Selection.Font.Size = 10
Selection.TypeText Text:="ABN: 22 333 111 555"
Selection.TypeParagraph
Selection.Font.Size = 12
Selection.TypeText Text:="22 Kings St, Sydney 2000"
Selection.TypeParagraph
Selection.TypeText Text:="Phone: (02) 9675 4444 Fax: (02) 9675 4443"
End Sub
Reply With Quote
  #2  
Old 08-28-2011, 10:58 PM
nutrastat nutrastat is offline Macro - Microsoft Word 2010 Windows 7 64bit Macro - Microsoft Word 2010 Office 2010 32bit
Advanced Beginner
 
Join Date: Aug 2011
Location: Brighton, UK
Posts: 36
nutrastat is on a distinguished road
Default

Hi,

I do not know the answer to the macro question, but I do have two alternative suggestions if you are interested…

Create a template file with the heading already created, although I'm assuming you already know that.

However, the better way would be to create a Quick Part, the new building blocks created for Microsoft Word.

Highlight all of this text. Go to insert, quick parts, save selection to gallery, putting a title of company address, creating new category called company, and her as a quick part and not normal document and then finally insert as new paragraph in the final selection box.

This will create a building block and you will be able to go to insert, quick part and select this and the text with all the formatting you require will appear.

However, what Microsoft appear to hide is the fact that there is a shortcut key (F3) and therefore type's Comp and then hit the F3 key and your whole address should appear. This is a fantastic new utility, which will allow you to save different types of text, with all formatting and to include graphics if you so require.

Hope this helps.
Reply With Quote
  #3  
Old 10-17-2011, 11:16 PM
Magid Magid is offline Macro - Microsoft Word 2010 Windows 7 32bit Macro - Microsoft Word 2010 Office 2010 32bit
Novice
 
Join Date: Oct 2011
Posts: 1
Magid is on a distinguished road
Default

Quote:
Originally Posted by OfficeHelpSG View Post
Hello,
I'm using Microsoft Word 2010, and every Macro I try and create for a letterhead, does not work. The formatting of my text is not shown when I run the macro! The size changes, and the bold does not apply. The weird thing is everytime I run the macro in the same document or in a different document, it doesnt ever show the same.
I'd like a letterhead macro to turn out like this (The top line should be in 16, the second line in 10 and the last two lines in size 12):

Turner and Sons Accouting Pty Ltd
ABN: 22 333 111 555
22 Kings St, Sydney 2000
Phone: (02) 9675 4444 Fax: (02) 9675 4443


The code for the text is:
Sub Letterhead()
'
' Letterhead Macro
'
'
Selection.TypeText Text:="Turner and Sons Accounting Pty Ltd"
Selection.TypeParagraph
Selection.Font.Bold = wdToggle
Selection.Font.Size = 10
Selection.TypeText Text:="ABN: 22 333 111 555"
Selection.TypeParagraph
Selection.Font.Size = 12
Selection.TypeText Text:="22 Kings St, Sydney 2000"
Selection.TypeParagraph
Selection.TypeText Text:="Phone: (02) 9675 4444 Fax: (02) 9675 4443"
End Sub
I also have a similar problem with office 2003,2007,2010
I am test macro in word 2003,2007 and 2010
Macro
does not apply font and size
Can you help me for this Problem??
Reply With Quote
  #4  
Old 10-18-2011, 11:54 AM
Stefan Blom's Avatar
Stefan Blom Stefan Blom is offline Macro - Microsoft Word 2010 Windows 7 64bit Macro - Microsoft Word 2010 Office 2010 32bit
Moderator
 
Join Date: Aug 2011
Posts: 3,907
Stefan Blom is a name known to allStefan Blom is a name known to allStefan Blom is a name known to allStefan Blom is a name known to allStefan Blom is a name known to allStefan Blom is a name known to all
Default

Using Building Blocks or a template would be a lot easier.

The basic problem with the macro is that the selection changes as you run it, which is why the formatting won't get applied to the paragraphs where you want it.

If you insist on using a macro, you would have to do something like this instead:

Code:
 
Sub ApplyDirectFormattingToText()
Dim r As Range
Set r = Selection.Range
With r
.Collapse wdCollapseEnd
.InsertAfter "First paragraph" ' replace with your text!
.InsertParagraphAfter
.InsertAfter "Second paragraph"
.InsertParagraphAfter
.InsertAfter "Third paragraph"
.InsertParagraphAfter
.InsertAfter "Fourth paragraph"
.Font.Name = "Arial"
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Paragraphs(1).Range.Font.Size = 16
.Paragraphs(1).Range.Font.Bold = True
.Paragraphs(2).Range.Font.Size = 10
 
.Paragraphs(3).Range.Font.Size = 12
.Paragraphs(4).Range.Font.Size = 12
End With
End Sub
You could make the macro more effective by having it apply styles to text paragraphs instead.
__________________
Stefan Blom
Microsoft Word MVP

Microsoft 365 apps for business
Windows 11 Professional
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro - Microsoft Word 2010 Microsoft Word 2010 - Aligning table horizontally SWEngineer Word Tables 4 07-20-2011 01:32 AM
Macro - Microsoft Word 2010 Run a Macro in Word 2010 Joyce301 Word VBA 3 04-29-2011 03:27 PM
Make text permanent in Microsoft Word 2010, how? shaunzo101 Word 0 09-21-2010 08:27 PM
Please help with a macro in Microsoft Word 2007 AKMMS Word VBA 0 06-23-2010 02:16 PM
Word 2003 macro to Word 2007 to 2010 to... maruapo Word VBA 0 06-04-2010 03:43 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:50 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft