avoiding empty lines with bookmarks

S

Simon K

Hi,

I'm new to office macroes, hence the perhaps unlogically workaround
suggestion.

I have an accounting program (Microsoft C5) that is able to print
invoices to a word .dot template. The template has simple bookmarks
where the invoice fields should go. But sometimes fields have empty
values and the leave a blank line in the document.

I would like to able to check for an empty value (or maybe the
bookmark is not even created?), so that I can remove the empty line in
the creation of the invoice document.

How is this best done? I have tried to tie a macro to the .dot
bookmark that checks the length of it, but it seems, it is not
executed. Also when I look at the created document the bookmarks can't
be found. So it seems I can only access the bookmarks in the .dot
file?

Any hints and help is very much appreciated.

Best regards
Simon K
 
J

Jean-Guy Marcil

Simon K was telling us:
Simon K nous racontait que :
Hi,

I'm new to office macroes, hence the perhaps unlogically workaround
suggestion.

I have an accounting program (Microsoft C5) that is able to print
invoices to a word .dot template. The template has simple bookmarks
where the invoice fields should go. But sometimes fields have empty
values and the leave a blank line in the document.

I would like to able to check for an empty value (or maybe the
bookmark is not even created?), so that I can remove the empty line in
the creation of the invoice document.

How is this best done? I have tried to tie a macro to the .dot
bookmark that checks the length of it, but it seems, it is not
executed. Also when I look at the created document the bookmarks can't
be found. So it seems I can only access the bookmarks in the .dot
file?

Any hints and help is very much appreciated.


"I have tried to tie a macro to the .dot"

What macro have you written and how did you try to get it to execute?

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
S

Simon K

Hi Jean-Guy. Thank you for answering.
What macro have you written and how did you try to get it to execute?

I tried this macro to test, if I could at all execute the macro.
Executed manually in the .dot file it worked.

Sub macro1()
Dim strB As String
strB =
ThisDocument.Bookmarks("ModtagerAdresse2").Range.Characters.Count
MsgBox strB
End Sub

Then in the textfield, that is used to send information from Microsoft
C5 to the document, I inserted "macro1()" in the field "play macro at"
"exit".

/Simon K
 
J

Jean-Guy Marcil

Simon K was telling us:
Simon K nous racontait que :
Hi Jean-Guy. Thank you for answering.


I tried this macro to test, if I could at all execute the macro.
Executed manually in the .dot file it worked.

Sub macro1()
Dim strB As String
strB =
ThisDocument.Bookmarks("ModtagerAdresse2").Range.Characters.Count
MsgBox strB
End Sub

Then in the textfield, that is used to send information from Microsoft
C5 to the document, I inserted "macro1()" in the field "play macro at"
"exit".

And where did you store this macro so that it could be executed from the
textfield in Microsoft C5?

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jean-Guy Marcil

Simon K was telling us:
Simon K nous racontait que :
I stored it with the visual basic editor in the
TemplateProject-Modules-NewMacros

The template project of which document/template?


--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
S

Simon K

The template project of which document/template?
the template project of the ordfakturaDK.dot that contains the
textfields, that is updated with the invoice info from Microsoft C5
when the page is untitled.doc is beeing opened. Microsoft C5 +
ordfakturaDK.dot = untitled.doc (the invoice ready for print).

Best regards
Simon K
 
J

Jean-Guy Marcil

Simon K was telling us:
Simon K nous racontait que :
the template project of the ordfakturaDK.dot that contains the
textfields, that is updated with the invoice info from Microsoft C5
when the page is untitled.doc is beeing opened. Microsoft C5 +
ordfakturaDK.dot = untitled.doc (the invoice ready for print).

To summarize:
You have a template named "ordfakturaDK.dot".
In this template, you created the following macro stored in the NewMacros
module:

Sub macro1()
Dim strB As String
strB =
ThisDocument.Bookmarks("ModtagerAdresse2").Range.Characters.Count
MsgBox strB
End Sub

This template also contains a text field which is set to run Macro1 onExit
You protected the template for forms and saved it.
Then you created a document based on the "ordfakturaDK.dot".
The macro does not execute when you leave the text field.

Is all of this correct?

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
S

Simon K

To summarize:
You have a template named "ordfakturaDK.dot".
In this template, you created the following macro stored in the NewMacros
module:

Sub macro1()
Dim strB As String
strB =
ThisDocument.Bookmarks("ModtagerAdresse2").Range.Characters.Count
MsgBox strB
End Sub

This template also contains a text field which is set to run Macro1 onExit
You protected the template for forms and saved it.
Then you created a document based on the "ordfakturaDK.dot".
The macro does not execute when you leave the text field.

Is all of this correct?

Hi Jean-Guy
This is all correct, except the part about protecting the form. When I
tried that, the text field weren't updated when the .doc was created.
Best regards
Simon K
 
J

Jean-Guy Marcil

Simon K was telling us:
Simon K nous racontait que :
Hi Jean-Guy
This is all correct, except the part about protecting the form. When I
tried that, the text field weren't updated when the .doc was created.

I do not understand the relationship between the fields being updated and
the creation of documents from the "ordfakturaDK.dot" template.
If the document is not protected, the OnExit macros will not be called.

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
S

Simon K

If the document is not protected, the OnExit macros will not be called.

But if the document IS protected, the fields will not get updated!? -
in my document it appears.

Best regards
Simon K
 
G

Graham Mayor

You can update fields with code run on exit, or you may simply need to check
the calculate on exit property of the form fields in question. For the
former - see http://www.gmayor.com/installing_macro.htm

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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