A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Page Layout
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Problems creating Macros



 
 
Thread Tools Display Modes
  #1  
Old May 13th, 2008, 03:36 AM posted to microsoft.public.word.pagelayout
Gabe
external usenet poster
 
Posts: 83
Default Problems creating Macros

I'm trying to create a macro to change my margins, make a document have 2
cols., and insert a page number at the end of the page using a keybord
command.
No matter how I try or which order I try these steps, I get the debug error
5941.
I don't know what that means, I don't know what i've done wrong.

Can anybody help?

Thanks,

Gabe
  #2  
Old May 13th, 2008, 04:01 AM posted to microsoft.public.word.pagelayout
Suzanne S. Barnhill
external usenet poster
 
Posts: 31,786
Default Problems creating Macros

Can you explain why you're using a macro instead of a template for this?

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA

"Gabe" wrote in message
...
I'm trying to create a macro to change my margins, make a document have 2
cols., and insert a page number at the end of the page using a keybord
command.
No matter how I try or which order I try these steps, I get the debug
error
5941.
I don't know what that means, I don't know what i've done wrong.

Can anybody help?

Thanks,

Gabe



  #3  
Old May 13th, 2008, 12:57 PM posted to microsoft.public.word.pagelayout
StevenM
external usenet poster
 
Posts: 36
Default Problems creating Macros

Assuming you need more than one page setup, you might try modifing the
following to your needs. If you only need one page setup, you should create a
new template.

Sub TestPageSetup()
Dim nColumns As Long
Dim pColWidth As Single
Dim pColGutter As Single
Dim pTop As Single
Dim pBottom As Single
Dim pLeft As Single
Dim pRight As Single
Dim pWidth As Single
Dim oRange As Range
Dim footerRange As Range

pTop = 6
pBottom = 6
pLeft = 6.5
pRight = 6.5
pColGutter = 3
nColumns = 2
pColWidth = (51 - (pColGutter + pRight + pLeft)) / nColumns

Set oRange = ActiveDocument.Range(Start:=ActiveDocument.Range.S tart,
End:=ActiveDocument.Range.End)

With oRange.PageSetup
.TopMargin = PicasToPoints(pTop)
.BottomMargin = PicasToPoints(pBottom)
.LeftMargin = PicasToPoints(pLeft)
.RightMargin = PicasToPoints(pRight)
End With

With oRange.PageSetup.TextColumns
.SetCount NumColumns:=nColumns
.EvenlySpaced = True
.LineBetween = False
.Width = PicasToPoints(pColWidth)
.Spacing = PicasToPoints(pColGutter)
End With

Set footerRange = oRange.Sections(1).Footers(wdHeaderFooterPrimary). Range

With footerRange
.Delete
With .ParagraphFormat.TabStops
.ClearAll
pWidth = 51 - (pLeft + pRight)
.Add Position:=PicasToPoints(pWidth / 2),
Alignment:=wdAlignTabCenter
.Add Position:=PicasToPoints(pWidth), Alignment:=wdAlignTabRight
End With
.InsertAfter vbTab & vbTab & "Page "
.MoveEnd unit:=wdCharacter, Count:=1
.Collapse wdCollapseEnd
oRange.Fields.Add Range:=footerRange, Type:=wdFieldPage
.MoveEnd unit:=wdCharacter, Count:=1
.Collapse wdCollapseEnd
.InsertAfter vbCr
End With
End Sub


"Gabe" wrote:

I'm trying to create a macro to change my margins, make a document have 2
cols., and insert a page number at the end of the page using a keybord
command.
No matter how I try or which order I try these steps, I get the debug error
5941.
I don't know what that means, I don't know what i've done wrong.

Can anybody help?

Thanks,

Gabe

  #4  
Old May 13th, 2008, 10:56 PM posted to microsoft.public.word.pagelayout
Gabe
external usenet poster
 
Posts: 83
Default Problems creating Macros

I guess I should have said I'm trying to RECORD a macro, I don't know
anything about the language you're using, maybe I should. I'll look into
creating a Template.

By the way someone sent me an email with a website that they said would
answer my question. The website was blank.

Thanks,

Gabe

"Gabe" wrote:

I'm trying to create a macro to change my margins, make a document have 2
cols., and insert a page number at the end of the page using a keybord
command.
No matter how I try or which order I try these steps, I get the debug error
5941.
I don't know what that means, I don't know what i've done wrong.

Can anybody help?

Thanks,

Gabe

  #5  
Old May 13th, 2008, 11:02 PM posted to microsoft.public.word.pagelayout
Gabe
external usenet poster
 
Posts: 83
Default Problems creating Macros


Suzanne:
That's a good question, BUT I don't know what a template is.
I do intend to find out.
I have been using Word/97 and it was very easy to record a Macro to do what
I've been trying to do in Word/2007.
I guess my statment should have been I'm trying to RECORD a Macro.

Thanks,

Gabe

"Suzanne S. Barnhill" wrote:

Can you explain why you're using a macro instead of a template for this?

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA

"Gabe" wrote in message
...
I'm trying to create a macro to change my margins, make a document have 2
cols., and insert a page number at the end of the page using a keybord
command.
No matter how I try or which order I try these steps, I get the debug
error
5941.
I don't know what that means, I don't know what i've done wrong.

Can anybody help?

Thanks,

Gabe




  #6  
Old May 13th, 2008, 11:12 PM posted to microsoft.public.word.pagelayout
Suzanne S. Barnhill
external usenet poster
 
Posts: 31,786
Default Problems creating Macros

The reason I asked is that everything you're trying to do with a macro can
be achieved much more simply in a template; see
http://word.mvps.org/FAQs/Customizat...platePart1.htm.

When you don't choose any other template, your documents are based on
Normal.dot (or Normal.dotm in Word 2007), but you can have as many templates
as you like, and it makes sense to create a template for any specific type
of formatting you use frequently. If you use some different settings for
*all* documents, you may want to customize Normal.dot instead (see
http://word.mvps.org/FAQs/Customizat...lTemplate.htm), but
adding page numbers or columns to Normal.dot is not recommended.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA

"Gabe" wrote in message
...

Suzanne:
That's a good question, BUT I don't know what a template is.
I do intend to find out.
I have been using Word/97 and it was very easy to record a Macro to do
what
I've been trying to do in Word/2007.
I guess my statment should have been I'm trying to RECORD a Macro.

Thanks,

Gabe

"Suzanne S. Barnhill" wrote:

Can you explain why you're using a macro instead of a template for this?

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA

"Gabe" wrote in message
...
I'm trying to create a macro to change my margins, make a document have
2
cols., and insert a page number at the end of the page using a keybord
command.
No matter how I try or which order I try these steps, I get the debug
error
5941.
I don't know what that means, I don't know what i've done wrong.

Can anybody help?

Thanks,

Gabe







  #7  
Old May 14th, 2008, 06:06 AM posted to microsoft.public.word.pagelayout
Graham Mayor
external usenet poster
 
Posts: 18,297
Default Problems creating Macros

http://www.gmayor.com/installing_macro.htm will explain what to do with vba
listings.

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



Gabe wrote:
I guess I should have said I'm trying to RECORD a macro, I don't know
anything about the language you're using, maybe I should. I'll look
into creating a Template.

By the way someone sent me an email with a website that they said
would answer my question. The website was blank.

Thanks,

Gabe

"Gabe" wrote:

I'm trying to create a macro to change my margins, make a document
have 2 cols., and insert a page number at the end of the page using
a keybord command.
No matter how I try or which order I try these steps, I get the
debug error 5941.
I don't know what that means, I don't know what i've done wrong.

Can anybody help?

Thanks,

Gabe



  #8  
Old May 14th, 2008, 12:58 PM posted to microsoft.public.word.pagelayout
StevenM
external usenet poster
 
Posts: 36
Default Problems creating Macros

There is also an old-fashioned resource, one which some of us old-timers
still like to use, it is called a “book.” It might be hard for some of you
youngsters to imagine, but some of us old-timers read information on paper as
well as information on a screen. And I’m not talking about a printout, but
something more than a handful of loose pages. A “book” is actually pages of
printed paper sewn (or glued) together, with a cloth (or cardboard) cover. I
would recommend you finding a book on Microsoft Word, they will have chapters
on creating a template, or working with macros. Such books usually go into
more detail than the (otherwise wonder) tutorials you find on the Internet.
You can find books for sale (new and used) on the Internet, or you can try
locating a place which warehouses and sells them, it is called a “bookstore.”
Just ask any old geezer where one might be, they will be able to give you
directions.

"Gabe" wrote:

I guess I should have said I'm trying to RECORD a macro, I don't know
anything about the language you're using, maybe I should. I'll look into
creating a Template.

By the way someone sent me an email with a website that they said would
answer my question. The website was blank.

Thanks,

Gabe

"Gabe" wrote:

I'm trying to create a macro to change my margins, make a document have 2
cols., and insert a page number at the end of the page using a keybord
command.
No matter how I try or which order I try these steps, I get the debug error
5941.
I don't know what that means, I don't know what i've done wrong.

Can anybody help?

Thanks,

Gabe

  #9  
Old August 7th, 2008, 06:51 PM posted to microsoft.public.word.pagelayout
USEN
external usenet poster
 
Posts: 16
Default Problems creating Macros

Hi Steven,

You seem to know quite a bit about Macros & VBA...perhaps you can help me as
well....

I have Office 2007, but I've designed a template and a Macro for an
employer who has people using both Word 2002 and 2003. Since it's for
someone else with a different versions of Word, I can't store it normally.
Since I don't know the file structure of their computers, I figured it would
be best to just create a folder on my C-drive so that they can store it in
the same place when I send it to them. Here's the problem.

I've designed 2 templates. The first template needs to call up the 2nd and
place the contents of the 2nd template at the top of various pages in the 1st
one. That's where the macro comes in. It inserts a page break then opens
the 2nd template, copies the contents and then pastes those contents at the
top of the new page. I purposely instructed the Macro so save in the
normal.dotm file so that it could be run from any other file when the
keyboard shortcut is used. It works like a charm from within the first
template as long as the template itself is open. However, when I attempt to
use the template as it is designed to be used...meaning that it opens a copy
of itself in a temporary document (Document1, Document2, etc.), then the
Macro fails to work. I get errors stating that part of the component set is
missing...the actual template that has opened a copy of itself instead of the
original.

I've deleted and re-recorded this Macro so many times...but the results are
always the same. What am I doing wrong? I have been trying to get this done
for over 5 hours now. Is it because the documents are not being stored in
the folders that Word normally stores them in?

Can anyone please give me some suggestions?

Thanks!
USEN

"StevenM" wrote:

Assuming you need more than one page setup, you might try modifing the
following to your needs. If you only need one page setup, you should create a
new template.

Sub TestPageSetup()
Dim nColumns As Long
Dim pColWidth As Single
Dim pColGutter As Single
Dim pTop As Single
Dim pBottom As Single
Dim pLeft As Single
Dim pRight As Single
Dim pWidth As Single
Dim oRange As Range
Dim footerRange As Range

pTop = 6
pBottom = 6
pLeft = 6.5
pRight = 6.5
pColGutter = 3
nColumns = 2
pColWidth = (51 - (pColGutter + pRight + pLeft)) / nColumns

Set oRange = ActiveDocument.Range(Start:=ActiveDocument.Range.S tart,
End:=ActiveDocument.Range.End)

With oRange.PageSetup
.TopMargin = PicasToPoints(pTop)
.BottomMargin = PicasToPoints(pBottom)
.LeftMargin = PicasToPoints(pLeft)
.RightMargin = PicasToPoints(pRight)
End With

With oRange.PageSetup.TextColumns
.SetCount NumColumns:=nColumns
.EvenlySpaced = True
.LineBetween = False
.Width = PicasToPoints(pColWidth)
.Spacing = PicasToPoints(pColGutter)
End With

Set footerRange = oRange.Sections(1).Footers(wdHeaderFooterPrimary). Range

With footerRange
.Delete
With .ParagraphFormat.TabStops
.ClearAll
pWidth = 51 - (pLeft + pRight)
.Add Position:=PicasToPoints(pWidth / 2),
Alignment:=wdAlignTabCenter
.Add Position:=PicasToPoints(pWidth), Alignment:=wdAlignTabRight
End With
.InsertAfter vbTab & vbTab & "Page "
.MoveEnd unit:=wdCharacter, Count:=1
.Collapse wdCollapseEnd
oRange.Fields.Add Range:=footerRange, Type:=wdFieldPage
.MoveEnd unit:=wdCharacter, Count:=1
.Collapse wdCollapseEnd
.InsertAfter vbCr
End With
End Sub


"Gabe" wrote:

I'm trying to create a macro to change my margins, make a document have 2
cols., and insert a page number at the end of the page using a keybord
command.
No matter how I try or which order I try these steps, I get the debug error
5941.
I don't know what that means, I don't know what i've done wrong.

Can anybody help?

Thanks,

Gabe

  #10  
Old August 9th, 2008, 09:51 AM posted to microsoft.public.word.pagelayout
Doug Robbins - Word MVP
external usenet poster
 
Posts: 8,239
Default Problems creating Macros

I responded to your identical post in the VBA General Newsgroup - admitedly
without giving a direct solution to your problem, but advising that you
would have to provide more information (the code at least) to be able to
provide assistance.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"USEN" wrote in message
...
Hi Steven,

You seem to know quite a bit about Macros & VBA...perhaps you can help me
as
well....

I have Office 2007, but I've designed a template and a Macro for an
employer who has people using both Word 2002 and 2003. Since it's for
someone else with a different versions of Word, I can't store it normally.
Since I don't know the file structure of their computers, I figured it
would
be best to just create a folder on my C-drive so that they can store it
in
the same place when I send it to them. Here's the problem.

I've designed 2 templates. The first template needs to call up the 2nd
and
place the contents of the 2nd template at the top of various pages in the
1st
one. That's where the macro comes in. It inserts a page break then opens
the 2nd template, copies the contents and then pastes those contents at
the
top of the new page. I purposely instructed the Macro so save in the
normal.dotm file so that it could be run from any other file when the
keyboard shortcut is used. It works like a charm from within the first
template as long as the template itself is open. However, when I attempt
to
use the template as it is designed to be used...meaning that it opens a
copy
of itself in a temporary document (Document1, Document2, etc.), then the
Macro fails to work. I get errors stating that part of the component set
is
missing...the actual template that has opened a copy of itself instead of
the
original.

I've deleted and re-recorded this Macro so many times...but the results
are
always the same. What am I doing wrong? I have been trying to get this
done
for over 5 hours now. Is it because the documents are not being stored in
the folders that Word normally stores them in?

Can anyone please give me some suggestions?

Thanks!
USEN

"StevenM" wrote:

Assuming you need more than one page setup, you might try modifing the
following to your needs. If you only need one page setup, you should
create a
new template.

Sub TestPageSetup()
Dim nColumns As Long
Dim pColWidth As Single
Dim pColGutter As Single
Dim pTop As Single
Dim pBottom As Single
Dim pLeft As Single
Dim pRight As Single
Dim pWidth As Single
Dim oRange As Range
Dim footerRange As Range

pTop = 6
pBottom = 6
pLeft = 6.5
pRight = 6.5
pColGutter = 3
nColumns = 2
pColWidth = (51 - (pColGutter + pRight + pLeft)) / nColumns

Set oRange = ActiveDocument.Range(Start:=ActiveDocument.Range.S tart,
End:=ActiveDocument.Range.End)

With oRange.PageSetup
.TopMargin = PicasToPoints(pTop)
.BottomMargin = PicasToPoints(pBottom)
.LeftMargin = PicasToPoints(pLeft)
.RightMargin = PicasToPoints(pRight)
End With

With oRange.PageSetup.TextColumns
.SetCount NumColumns:=nColumns
.EvenlySpaced = True
.LineBetween = False
.Width = PicasToPoints(pColWidth)
.Spacing = PicasToPoints(pColGutter)
End With

Set footerRange =
oRange.Sections(1).Footers(wdHeaderFooterPrimary). Range

With footerRange
.Delete
With .ParagraphFormat.TabStops
.ClearAll
pWidth = 51 - (pLeft + pRight)
.Add Position:=PicasToPoints(pWidth / 2),
Alignment:=wdAlignTabCenter
.Add Position:=PicasToPoints(pWidth),
Alignment:=wdAlignTabRight
End With
.InsertAfter vbTab & vbTab & "Page "
.MoveEnd unit:=wdCharacter, Count:=1
.Collapse wdCollapseEnd
oRange.Fields.Add Range:=footerRange, Type:=wdFieldPage
.MoveEnd unit:=wdCharacter, Count:=1
.Collapse wdCollapseEnd
.InsertAfter vbCr
End With
End Sub


"Gabe" wrote:

I'm trying to create a macro to change my margins, make a document have
2
cols., and insert a page number at the end of the page using a keybord
command.
No matter how I try or which order I try these steps, I get the debug
error
5941.
I don't know what that means, I don't know what i've done wrong.

Can anybody help?

Thanks,

Gabe



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:50 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright 2004-2024 OfficeFrustration.
The comments are property of their posters.