InchesToPoints?

R

R. Choate

Below is a snippet of my code that has been used for years. This works, but I admit I don't really understand the "InchesToPoints"
thing. I inherited this code and just used it because it worked. Now I have a chance to improve the whole project and this is one
thing I want to ask about. Isn't there a better way of identifying margins and indentations using instructions which just refer to
inches without all of this extra garbage? Can somebody tell me what this is about?

Thank you very much in advance. I will appreciate this.

With ActiveDocument.PageSetup
.TopMargin = InchesToPoints(1)
.BottomMargin = InchesToPoints(1)

Richard
 
O

old man

Hi,

This is not garbage. There are 72 points per inch and to set the margins you
need to set then number of points for the top and bottom margin. The
inchestopoints function allows someone to specify in inches how big the
margin is instead of specifying points.

What I want to know what is this garbage about double entry bookkeeping?

old man
 
R

R. Choate

I was not trying to rub somebody the wrong way. I merely am interested in having code which will be able to directly specify inches
without requiring conversion. Why the wisecrack about double entry bookkeeping? I have a real situation, I'm not rude to anybody,
I'm not cross-posting in several NGs at once, and I don't understand your comments. If you needed help in Excel or Excel VBA or
Access db (my main apps), I would not treat you this way; I would try to help you if I knew the answer. Now, somebody who knows how
to help me may not reply because they see there is already a response. However, your response is not help, it is criticism and
ridicule. Please don't do that.

--
RMC,CPA


Hi,

This is not garbage. There are 72 points per inch and to set the margins you
need to set then number of points for the top and bottom margin. The
inchestopoints function allows someone to specify in inches how big the
margin is instead of specifying points.

What I want to know what is this garbage about double entry bookkeeping?

old man
 
G

Graham Mayor

Word measures internally in points. In order to use inches or centimetres
you have to convert them to points.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
R

Russ

This is a snippet from a previous thread.
Word has all kinds of VBA point conversion functions.
======================================================
 
R

R. Choate

Thanks Graham, you have now confirmed for me that the conversion I was doing back in 2000 is still necessary and cannot be replaced
with something else that is more "elegant" and less cumbersome. I'm sure you understand my interest in at least asking about it. My
VBA code in my Word template has in some cases run over the size limit for a module because I had to account for so many
combinations of letters. Since I am revisiting it now, I was hoping I could find some places to eliminate code or write shorter and
more efficient code (yes, I know that those two things do not necessarily go together).

Anyway, I appreciate your response. I was very tired last night after another long, late night of work, and the responses I got from
"old man" just didn't help and came at the wrong time in the wrong way. I'm sure you will see more questions through this evening if
you are monitoring the NG. I think I will be doing the same again tonight if my eyes don't shut on me.

Richard
--
RMC,CPA


Word measures internally in points. In order to use inches or centimetres
you have to convert them to points.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
J

Jay Freedman

Hi Richard,

One more assurance about your code: VBA doesn't store the long names
of built-in functions like InchesToPoints in the file. These things
are stored as 32-bit handles that point into a function table.
Variable names, literal strings and numbers, and comments are stored
character-for-character. It wouldn't matter if you were able to use a
different function with a shorter name, the stored file wouldn't be
any smaller.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
T

Tony Strazzeri

Hi Richard,

I am curious about the comment you make below. I have some very large
Addins and templates (code-wise) and have not experienced any real
problems with the size. Can you expand on the problems you are
experiencing to make you need to reduce the size?

Maybe we can suggest other approaches that may be more useful.

Cheers
TonyS.
 
R

R. Choate

Hi Tony,

I think I was probably confusing on this issue as well; I am not a novice in VBA, or really all that much with Word. After all, I
did create this large app with a multi-tab strip and lots of controls which moved around and hidden or shown on the fly, both to
conserve space and because of contextual reasons. My "macro" also makes use of ADO to connect to some disconnected, stored
recordsets, as well as the ability to refresh/replace those little recordsets with new ones when the user is able to connect to the
network. Additionally, this particular app hooks up with Goldmine db because of the contact data held there, it can create and
insert multiple tables on the fly with user specs for both placement of the tables and width of columns, etc.. I could go on, it
does a lot of stuff, but still this is not my "home" app.. That distinction goes to Excel hosted VBA, closely followed by Access and
the requisite code for that. Having said all of that, the answer to your question is that I had to break up some modules because I
went over the 64kb size limit for a single procedure (maybe it is a single module...it has been a long time). I'll bet that limit
still existed up to and maybe including the new version of Office. The reason I went over was because I had to account for all of
the combinations of letters which one might encounter under certain conditions for a particular category of client letter. That
category just had lots of combinations and elements at the time. I was primarily using 2 comboboxes on that page of the form, and
had to make heavy use of Select Case. The only problems were the combinations I had to account for. Given the situation, there was
no more efficient way to deal with it than using the Select Case in heavy doses.

Those issues were in regular modules anyway. The question I had about the inches to points thing is not anything which put me up
against the edge of the limit, I just don't like it and thought that surely there is a better way. Apparently not. Just the same,
thanks for your interest. I'm sure you will be able to take some stabs at my other questions as I re-enter the meat of this thing
again to make it smaller overall (because we are shifting a lot of functionality to another, "out of the box" program, not because
of code inefficiency).

As long as you are interested, nobody has really given me the direction I need on my question about calling one template from
another template. I'm about to re-post this problem after poorly expressing the situation last night and getting replies which
ranged from condescending to just dead ends. The deal is that I have the main app which I described above. Its function is to
generate letters. The file is a .dot so that everything which it creates is in the image of the template settings, plus it takes all
of these instructions from my code. Then there is template #2 which holds the letterhead. I need to use the letterhead with the
different 1st page setup. Somebody suggested after I explained in more detail that I can't have user intervention and the whole
thing must be done automatically, that I look into reading about auto-text in the Word VBA help and move my letterhead into the main
app. From what I found when I worked on this before, it didn't seem like a real possibility because 1. I don't want the letterhead
every time. 2. Some but not all letters are more than one page long, and having the letterhead in the "main" template seemed to get
bad results in that regard; I have tried it before. 3. There is a good bit of header and footer info in the "main" file's code
already and things seemed to go awry when introducing this letterhead which is in the header/footer layer already. That is, in the
template file for the letterhead, you don't see the letterhead with full color and contrast until you view headers and footers.
Having said that, I should mention that the letterhead doesn't seem to actually be a header or a footer, it just seems to be on that
same "graphics layer", for lack of a better term. Hopefully this makes more sense to you than to the other couple of guys who were
taking a stab at it. My fault all the way for not being more articulate (except for "old man", who was trying to be more
condescending than helpful). I was just trying my best not to over-describe a problem. Some won't help you if your description is
too long.

--
RMC,CPA


Hi Richard,

I am curious about the comment you make below. I have some very large
Addins and templates (code-wise) and have not experienced any real
problems with the size. Can you expand on the problems you are
experiencing to make you need to reduce the size?

Maybe we can suggest other approaches that may be more useful.

Cheers
TonyS.
 
T

Tony Strazzeri

Hi Richard,

Your app does seem complex, but that is not to say it needs to be.
For comparison (without bragging), my main addin is 5Mb. It has 19
userforms (mostly not overly complex), 27 modules (most a total of
over 280 procedures) and 3 class modules. It too gets data from
external databases using both ADO and DAO -if it's not broken I
(mostly) don't fiddle with it. It has references to other object
libraries such as OLE automation, scripting runtime, Jet, and control
libraries -it uses ListView and TreeView controls that are not native
to word VBA forms.

It also has references to other templates which provide other
functionality created by other developers within the organisation.
More on how this is done later.


I don't know how to measure the size of each module to see if it
exceeds the 64K limit you mention, but I have never had a problem with
that as far as I know. Where did you hear about that? Are you
automating word from Word templates or is that a problem when
automating from other apps?

This addin provides all of the functionality that is common to my
other individual templates. My main approach is that I have a
separate template for each discrete type of document I need to
produce. These templates contain the "words" that are to be produced
as well as the code that gets the data (both from the user and
databases) that the template needs.

My main approach is as follows.

SmartDoc(tm) Addin - this is a Word template that is automatically
loaded by Word (its in the Startup folder). This addin provides a menu
system from which the user selects the template they want (or even a
template or document from another app eg. spreadsheet, pdf, email).
Once the template is selected the menu then runs a specific procedure/
macro specified for that template. That procedure is in the selected
template. From here on, control is passed to the selected template.

The selected template calls a procedure in a third template which
contains code used to select the job/details for the job we are
working on eg names addresses, responsible partners etc. A job
selection screen is displayed and then the job data is retrieved from
a database and displayed on a form for checking. This common data
then populates the relevant places on the new document.

After this common data phase is complete the selected template macro
displays another form (remember all this code and the form is stored
in the selected template) allowing the user to enter information
specific to that template. The data is validated and then transferred
to the document.

So I have
One template with common procedures always accessible by other
templates (because it is always loaded at Word Startup). This
references external dll and OCX libraries as well as other templates
which make code available (through referencing).

One template that is only referenced by the selected template (through
referencing).

One selected template that accesses procedures from both of the above
templates.


So how does this work?
I hope this helps a little.

To access procedures between templates, the best way is to declare a
reference at design time.

For example Template A provides procedures to all other templates
Template A's procedures are accessible when it is opened/loaded by
word. This can be done in one of four ways.
1. The template is opened directly by word (using File|Open)
2. The template is loaded automatically by Word by being in Word's
Startup folder
3. The template is opened automatically by Word by being specified in
the "Global Templates and Addins". Tools|Templates and Addins"
Templates tab and click the Add button.
4. The template is loaded automatically by being referenced in the VBA
IDE. To do this Open the IDE and select Tools|References.

My SmartDoc(tm) is loaded using the first method. It referenced the
other templates using the fourth method.
The selected template accesses procedures in the common template also
using the fourth method.

The trick to simplifying this is to assign a meaningful project name
to the template to be referenced. This is done from the VBA IDE. Open
the template, and then switch to the IDE. In the IDE select the
template from the Projects window. It will be listed as
"TemplateProject (x)" or "Project (x)", where x is the name of the
document. Right click on the project and select the Project
Properties. You can now assign a project name to the template. If
you keep this short and meaningful it will help immensely). For
example my SmartDoc addin template project name is ... drum roll
please..... "SmartDoc".

Now whenever the template is loaded (via any of the above four
methods) it will appear in the Reference list as "SmartDoc".

If you need to use any procedures from an external template you simple
add a reference to the template project name at design time.

So in the above example the selected template has a reference to the
SmartDoc Addin as well as to the template providing the common job
type related procedures (in my case I have two called "CRGcommon" and
"Admincommon").

Any public procedures in either template can now be accessed simply by
using its name.

Eg here are two procedures.
One in SmartDoc
If SmartDoc.ProgrammerTemplateTestExit Then Exit Sub

This one in AdminCommon
Call AdminCommon.modAdmin_DoitCommon.CalledFromDoc


As you probably know already, these can be simplified as;
If ProgrammerTemplateTestExit Then Exit Sub

AdminCommon.modAdmin_DoitCommon.CalledFromDoc
modAdmin_DoitCommon.CalledFromDoc
CalledFromDoc


I have just realised how much time I have spent on this reply so have
to cut it short. Sorry.

As for the rest of your response, I will just make some simple
comments which can maybe act as pointers to further discussion.

the combinations of letters which one might encounter under certain conditions for a particular category of client letter. That
category just had lots of combinations and elements at the time. I was primarily using 2 comboboxes on that page of the form, and

I usually use individual templates for each type of letter. I do try
to simplify/reduce numbers by combining text into a single template
and adding/removing as necessary under program control but if the
conditions when a certain text is retained or removed get too
complicated (nested conditions) I usually find it is simpler to code
and for the client to specify if there are separate templates.

generate letters. The file is a .dot so that everything which it creates is in the image of the template settings, plus it takes all
of these instructions from my code. Then there is template #2 which holds the letterhead. I need to use the letterhead with the
different 1st page setup. Somebody suggested after I explained in more detail that I can't have user intervention and the whole
thing must be done automatically, that I look into reading about auto-text in the Word VBA help and move my letterhead into the main

Sounds like you are substantially "constructing" the document content
on the fly. See above point on this.
I agree if you don't need the letterhead on every document then it may
not be appropriate to have it "hard-coded" in the template. On the
other hand how are you inserting it?
If it isn't in the document are you copying it from another source and
inserting it on the fly? If that is the case you could insert it from
autotext stored in one of the already loaded templates. If you are not
doing any of these then are you constructing it?

3. There is a good bit of header and footer info in the "main" file's code

So you are constructing it?
things seemed to go awry when introducing this letterhead which is in the header/footer
layer already. That is, in the template file for the letterhead, you don't see the letterhead
with full color and contrast until you view headers and footers.

That is as it should be. It will still print and output correctly.
It's like that more as a visual clue to the user as to where that
stuff is coming from (and by putting it there and not say, at the
start of the document first page, it reduces the possibility of the
user inadvertently moving/deleting it).

Cheers
TonyS.
 
R

R. Choate

I am not able to fully reply right now, but re the 64k limit, I learned of it when I went over it and it threw an error.

--
RMC,CPA


Hi Richard,

Your app does seem complex, but that is not to say it needs to be.
For comparison (without bragging), my main addin is 5Mb. It has 19
userforms (mostly not overly complex), 27 modules (most a total of
over 280 procedures) and 3 class modules. It too gets data from
external databases using both ADO and DAO -if it's not broken I
(mostly) don't fiddle with it. It has references to other object
libraries such as OLE automation, scripting runtime, Jet, and control
libraries -it uses ListView and TreeView controls that are not native
to word VBA forms.

It also has references to other templates which provide other
functionality created by other developers within the organisation.
More on how this is done later.


I don't know how to measure the size of each module to see if it
exceeds the 64K limit you mention, but I have never had a problem with
that as far as I know. Where did you hear about that? Are you
automating word from Word templates or is that a problem when
automating from other apps?

This addin provides all of the functionality that is common to my
other individual templates. My main approach is that I have a
separate template for each discrete type of document I need to
produce. These templates contain the "words" that are to be produced
as well as the code that gets the data (both from the user and
databases) that the template needs.

My main approach is as follows.

SmartDoc(tm) Addin - this is a Word template that is automatically
loaded by Word (its in the Startup folder). This addin provides a menu
system from which the user selects the template they want (or even a
template or document from another app eg. spreadsheet, pdf, email).
Once the template is selected the menu then runs a specific procedure/
macro specified for that template. That procedure is in the selected
template. From here on, control is passed to the selected template.

The selected template calls a procedure in a third template which
contains code used to select the job/details for the job we are
working on eg names addresses, responsible partners etc. A job
selection screen is displayed and then the job data is retrieved from
a database and displayed on a form for checking. This common data
then populates the relevant places on the new document.

After this common data phase is complete the selected template macro
displays another form (remember all this code and the form is stored
in the selected template) allowing the user to enter information
specific to that template. The data is validated and then transferred
to the document.

So I have
One template with common procedures always accessible by other
templates (because it is always loaded at Word Startup). This
references external dll and OCX libraries as well as other templates
which make code available (through referencing).

One template that is only referenced by the selected template (through
referencing).

One selected template that accesses procedures from both of the above
templates.


So how does this work?
I hope this helps a little.

To access procedures between templates, the best way is to declare a
reference at design time.

For example Template A provides procedures to all other templates
Template A's procedures are accessible when it is opened/loaded by
word. This can be done in one of four ways.
1. The template is opened directly by word (using File|Open)
2. The template is loaded automatically by Word by being in Word's
Startup folder
3. The template is opened automatically by Word by being specified in
the "Global Templates and Addins". Tools|Templates and Addins"
Templates tab and click the Add button.
4. The template is loaded automatically by being referenced in the VBA
IDE. To do this Open the IDE and select Tools|References.

My SmartDoc(tm) is loaded using the first method. It referenced the
other templates using the fourth method.
The selected template accesses procedures in the common template also
using the fourth method.

The trick to simplifying this is to assign a meaningful project name
to the template to be referenced. This is done from the VBA IDE. Open
the template, and then switch to the IDE. In the IDE select the
template from the Projects window. It will be listed as
"TemplateProject (x)" or "Project (x)", where x is the name of the
document. Right click on the project and select the Project
Properties. You can now assign a project name to the template. If
you keep this short and meaningful it will help immensely). For
example my SmartDoc addin template project name is ... drum roll
please..... "SmartDoc".

Now whenever the template is loaded (via any of the above four
methods) it will appear in the Reference list as "SmartDoc".

If you need to use any procedures from an external template you simple
add a reference to the template project name at design time.

So in the above example the selected template has a reference to the
SmartDoc Addin as well as to the template providing the common job
type related procedures (in my case I have two called "CRGcommon" and
"Admincommon").

Any public procedures in either template can now be accessed simply by
using its name.

Eg here are two procedures.
One in SmartDoc
If SmartDoc.ProgrammerTemplateTestExit Then Exit Sub

This one in AdminCommon
Call AdminCommon.modAdmin_DoitCommon.CalledFromDoc


As you probably know already, these can be simplified as;
If ProgrammerTemplateTestExit Then Exit Sub

AdminCommon.modAdmin_DoitCommon.CalledFromDoc
modAdmin_DoitCommon.CalledFromDoc
CalledFromDoc


I have just realised how much time I have spent on this reply so have
to cut it short. Sorry.

As for the rest of your response, I will just make some simple
comments which can maybe act as pointers to further discussion.

the combinations of letters which one might encounter under certain conditions for a particular category of client letter. That
category just had lots of combinations and elements at the time. I was primarily using 2 comboboxes on that page of the form, and

I usually use individual templates for each type of letter. I do try
to simplify/reduce numbers by combining text into a single template
and adding/removing as necessary under program control but if the
conditions when a certain text is retained or removed get too
complicated (nested conditions) I usually find it is simpler to code
and for the client to specify if there are separate templates.

generate letters. The file is a .dot so that everything which it creates is in the image of the template settings, plus it takes
all
of these instructions from my code. Then there is template #2 which holds the letterhead. I need to use the letterhead with the
different 1st page setup. Somebody suggested after I explained in more detail that I can't have user intervention and the whole
thing must be done automatically, that I look into reading about auto-text in the Word VBA help and move my letterhead into the
main

Sounds like you are substantially "constructing" the document content
on the fly. See above point on this.
I agree if you don't need the letterhead on every document then it may
not be appropriate to have it "hard-coded" in the template. On the
other hand how are you inserting it?
If it isn't in the document are you copying it from another source and
inserting it on the fly? If that is the case you could insert it from
autotext stored in one of the already loaded templates. If you are not
doing any of these then are you constructing it?

3. There is a good bit of header and footer info in the "main" file's code

So you are constructing it?
things seemed to go awry when introducing this letterhead which is in the header/footer
layer already. That is, in the template file for the letterhead, you don't see the letterhead
with full color and contrast until you view headers and footers.

That is as it should be. It will still print and output correctly.
It's like that more as a visual clue to the user as to where that
stuff is coming from (and by putting it there and not say, at the
start of the document first page, it reduces the possibility of the
user inadvertently moving/deleting it).

Cheers
TonyS.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top