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 » Mailmerge
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

make buttons invisible



 
 
Thread Tools Display Modes
  #1  
Old June 3rd, 2009, 08:02 PM posted to microsoft.public.word.mailmerge.fields
rutica[_7_]
external usenet poster
 
Posts: 1
Default make buttons invisible


I have a Microsoft Word 2003 document that has mail merge fields with
Excel as its data source.

I created a few command buttons on my main form. One button allows the
user to select the data source, one allows the user to select
recipients and the third Merges the data and creates a new document.

I would like those command buttons to *not* appear on the newly created
documents.

Here is my code for the button that creates the new document:

Private Sub cmdMergeDocument_Click()
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True

Me.cmdSelectDataSource.Visible = False 'this doesn't work!
Me.cmdMergeDocument.Visible = False 'this doesn't work!
Me.cmdSelectRecipients.Visible = False 'this doesn't work!

With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With

'now show the buttons again on the main form
Me.cmdSelectDataSource.Visible = True 'this doesn't work!
Me.cmdMergeDocument.Visible = True 'this doesn't work!
Me.cmdSelectRecipients.Visible = True 'this doesn't work!
End Sub

I get 'Object doesn't support this property or method'.

I am able to do: cmdSelectDataSource.Enabled = False, but it's not what
I need. I need the buttons invisible, not disabled.

Help!
Thanks,




--
rutica
  #2  
Old June 3rd, 2009, 10:05 PM posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP
external usenet poster
 
Posts: 8,239
Default make buttons invisible

See my response to your post of yesterday, or save the document as a
template to which you add a custom toolbar containing buttons to run your
code. ActiveX buttons are not suitable for use in a document that is to be
printed.

--
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, originally posted via msnews.microsoft.com
"rutica" wrote in message
...

I have a Microsoft Word 2003 document that has mail merge fields with
Excel as its data source.

I created a few command buttons on my main form. One button allows the
user to select the data source, one allows the user to select
recipients and the third Merges the data and creates a new document.

I would like those command buttons to *not* appear on the newly created
documents.

Here is my code for the button that creates the new document:

Private Sub cmdMergeDocument_Click()
With ActiveDocument.MailMerge
Destination = wdSendToNewDocument
SuppressBlankLines = True

Me.cmdSelectDataSource.Visible = False 'this doesn't work!
Me.cmdMergeDocument.Visible = False 'this doesn't work!
Me.cmdSelectRecipients.Visible = False 'this doesn't work!

With .DataSource
FirstRecord = wdDefaultFirstRecord
LastRecord = wdDefaultLastRecord
End With
Execute Pause:=False
End With

'now show the buttons again on the main form
Me.cmdSelectDataSource.Visible = True 'this doesn't work!
Me.cmdMergeDocument.Visible = True 'this doesn't work!
Me.cmdSelectRecipients.Visible = True 'this doesn't work!
End Sub

I get 'Object doesn't support this property or method'.

I am able to do: cmdSelectDataSource.Enabled = False, but it's not what
I need. I need the buttons invisible, not disabled.

Help!
Thanks,




--
rutica


  #3  
Old June 3rd, 2009, 10:20 PM posted to microsoft.public.word.mailmerge.fields
Peter Jamieson
external usenet poster
 
Posts: 4,550
Default make buttons invisible

Perhaps the best you can do is save their .Length and .Width properties,
set them each to 1 prior to the merge, then set them back to the saved
values.

Unless there is another approach that would fit your application, e.g.
you insert macrobutton fields and connect them to appropriate VBA
functions, then remove the buttons altogether prior to merging, then
re-insert them after.

Peter Jamieson

http://tips.pjmsn.me.uk

rutica wrote:
I have a Microsoft Word 2003 document that has mail merge fields with
Excel as its data source.

I created a few command buttons on my main form. One button allows the
user to select the data source, one allows the user to select
recipients and the third Merges the data and creates a new document.

I would like those command buttons to *not* appear on the newly created
documents.

Here is my code for the button that creates the new document:

Private Sub cmdMergeDocument_Click()
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True

Me.cmdSelectDataSource.Visible = False 'this doesn't work!
Me.cmdMergeDocument.Visible = False 'this doesn't work!
Me.cmdSelectRecipients.Visible = False 'this doesn't work!

With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With

'now show the buttons again on the main form
Me.cmdSelectDataSource.Visible = True 'this doesn't work!
Me.cmdMergeDocument.Visible = True 'this doesn't work!
Me.cmdSelectRecipients.Visible = True 'this doesn't work!
End Sub

I get 'Object doesn't support this property or method'.

I am able to do: cmdSelectDataSource.Enabled = False, but it's not what
I need. I need the buttons invisible, not disabled.

Help!
Thanks,




  #4  
Old June 4th, 2009, 06:56 PM posted to microsoft.public.word.mailmerge.fields
rutica[_8_]
external usenet poster
 
Posts: 1
Default make buttons invisible


thanks for writing.

Peter, I tried Me.cmdMergeDocument.Width = 1 and it works!

The only weird thing is setting it back to normal on the main document.
I want my height=45 and my width=117.

But for some reason, if my code lists the height first:
Me.cmdSelectDataSource.height =45
Me.cmdSelectDataSource.width=117
then both the height and the width are 117.

If i list the width first:
Me.cmdSelectDataSource.width=117
Me.cmdSelectDataSource.height=45
then both the height and the width are 45.

It's seems to only consider the last command and then apply that value
to both height and width?

Here is my code that shows both the height and width as 45:

With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource

'make the buttons small
Me.cmdMergeDocument.Width = 1
Me.cmdSelectDataSource.Width = 1
Me.cmdSelectRecipients.Width = 1

.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord

End With
.Execute Pause:=False
End With

'now re-size the buttons again
Me.cmdSelectDataSource.Width = 117
Me.cmdSelectDataSource.Height = 45

Me.cmdSelectRecipients.Width = 117
Me.cmdSelectRecipients.Height = 45

Me.cmdMergeDocument.Width = 117
Me.cmdMergeDocument.Height = 45

How can i make the width=117 and the height=45?

Weird.

Peter Jamieson;416392 Wrote:
Perhaps the best you can do is save their .Length and .Width properties,

set them each to 1 prior to the merge, then set them back to the saved

values.

Unless there is another approach that would fit your application, e.g.

you insert macrobutton fields and connect them to appropriate VBA
functions, then remove the buttons altogether prior to merging, then
re-insert them after.

Peter Jamieson

http://tips.pjmsn.me.uk

rutica wrote:-
I have a Microsoft Word 2003 document that has mail merge fields with
Excel as its data source.

I created a few command buttons on my main form. One button allows
the
user to select the data source, one allows the user to select
recipients and the third Merges the data and creates a new document.

I would like those command buttons to *not* appear on the newly
created
documents.

Here is my code for the button that creates the new document:

Private Sub cmdMergeDocument_Click()
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True

Me.cmdSelectDataSource.Visible = False 'this doesn't work!
Me.cmdMergeDocument.Visible = False 'this doesn't work!
Me.cmdSelectRecipients.Visible = False 'this doesn't work!

With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With

'now show the buttons again on the main form
Me.cmdSelectDataSource.Visible = True 'this doesn't work!
Me.cmdMergeDocument.Visible = True 'this doesn't work!
Me.cmdSelectRecipients.Visible = True 'this doesn't work!
End Sub

I get 'Object doesn't support this property or method'.

I am able to do: cmdSelectDataSource.Enabled = False, but it's not
what
I need. I need the buttons invisible, not disabled.

Help!
Thanks,



-





--
rutica
  #5  
Old June 4th, 2009, 09:01 PM posted to microsoft.public.word.mailmerge.fields
Peter Jamieson
external usenet poster
 
Posts: 4,550
Default make buttons invisible

I tried something more like


Dim intHeight As Integer
Dim intWidth As Integer

' save the button dimensions

intHeight = Me.cmdSelectDataSource.Height
intWidth = Me.cmdSelectDataSource.Width

' do the merge
'

' restore the button dimensions

Me.cmdSelectDataSource.Height = intHeight
Me.cmdSelectDataSource.Width = intWidth


It seems logically pretty much the same as yours, so
a. it is possible that mine wasn't working quite as I imagined. I'll
have anther look.
b. let's make sure we are using the same kind of buttons. Are you
using the standard "ActiveX" buttons (I think they are "Forms.2"
buttons)? I was actually testing with Word 2007 but I'll have a look
with Word 2003.

Peter Jamieson

http://tips.pjmsn.me.uk

rutica wrote:
thanks for writing.

Peter, I tried Me.cmdMergeDocument.Width = 1 and it works!

The only weird thing is setting it back to normal on the main document.
I want my height=45 and my width=117.

But for some reason, if my code lists the height first:
Me.cmdSelectDataSource.height =45
Me.cmdSelectDataSource.width=117
then both the height and the width are 117.

If i list the width first:
Me.cmdSelectDataSource.width=117
Me.cmdSelectDataSource.height=45
then both the height and the width are 45.

It's seems to only consider the last command and then apply that value
to both height and width?

Here is my code that shows both the height and width as 45:

With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource

'make the buttons small
Me.cmdMergeDocument.Width = 1
Me.cmdSelectDataSource.Width = 1
Me.cmdSelectRecipients.Width = 1

.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord

End With
.Execute Pause:=False
End With

'now re-size the buttons again
Me.cmdSelectDataSource.Width = 117
Me.cmdSelectDataSource.Height = 45

Me.cmdSelectRecipients.Width = 117
Me.cmdSelectRecipients.Height = 45

Me.cmdMergeDocument.Width = 117
Me.cmdMergeDocument.Height = 45

How can i make the width=117 and the height=45?

Weird.

Peter Jamieson;416392 Wrote:
Perhaps the best you can do is save their .Length and .Width properties,

set them each to 1 prior to the merge, then set them back to the saved

values.

Unless there is another approach that would fit your application, e.g.

you insert macrobutton fields and connect them to appropriate VBA
functions, then remove the buttons altogether prior to merging, then
re-insert them after.

Peter Jamieson

http://tips.pjmsn.me.uk

rutica wrote:-
I have a Microsoft Word 2003 document that has mail merge fields with
Excel as its data source.

I created a few command buttons on my main form. One button allows
the
user to select the data source, one allows the user to select
recipients and the third Merges the data and creates a new document.

I would like those command buttons to *not* appear on the newly
created
documents.

Here is my code for the button that creates the new document:

Private Sub cmdMergeDocument_Click()
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True

Me.cmdSelectDataSource.Visible = False 'this doesn't work!
Me.cmdMergeDocument.Visible = False 'this doesn't work!
Me.cmdSelectRecipients.Visible = False 'this doesn't work!

With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With

'now show the buttons again on the main form
Me.cmdSelectDataSource.Visible = True 'this doesn't work!
Me.cmdMergeDocument.Visible = True 'this doesn't work!
Me.cmdSelectRecipients.Visible = True 'this doesn't work!
End Sub

I get 'Object doesn't support this property or method'.

I am able to do: cmdSelectDataSource.Enabled = False, but it's not
what
I need. I need the buttons invisible, not disabled.

Help!
Thanks,



-





  #6  
Old June 9th, 2009, 02:32 AM posted to microsoft.public.word.mailmerge.fields
rutica[_9_]
external usenet poster
 
Posts: 1
Default make buttons invisible


Peter, thank for writing again. I tried your way, but still got the
same result.

Something is forcing my code to be a square, I can't get the height and
width to be different. I am using the 'Control toolbox' to create a
command button. (In Office 2003: View, Toolbars, Control Toolbox). I
don't know if that is ActiveX...

I was able to get around my problem by having the height and width both
75. That suits my needs, this time at least.

Below is my code (to test, I only tried it with the cmdSelectDataSource
button). But the code doesn't work. Again, the height and width for
cmdSelectDataSource is the same even though the message box I created
for testing below shows a different height and width.

My AutoSize property for the 3 buttons is set to False. Could it
somehow to related to that? I tested by changing them to True, but no
change.

Private Sub cmdMergeDocument_Click()
On Error GoTo Err_error_Click
'merge document-step 3
Dim intHeight As Integer
Dim intWidth As Integer

intHeight = Me.cmdSelectDataSource.Height
intWidth = Me.cmdSelectDataSource.Width

'display the height and width for testing purposes
MsgBox "height is: " & intHeight & " and width is: " & intWidth

If MsgBox("Are you sure you want to create a new document(s)?",
vbOKCancel, "Create documents") = vbCancel Then
Exit Sub
End If

'first check if the document if protected. If so, unprotect it. Opening
the document triggers code to protect it (see the Document_Open()
event)
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect "hi"
End If


With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource

'make the buttons small
Me.cmdMergeDocument.Width = 1
Me.cmdSelectDataSource.Width = 1
Me.cmdSelectRecipients.Width = 1

.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord

End With
.Execute Pause:=False
End With

'now re-size the buttons again
Me.cmdSelectDataSource.Height = intHeight
Me.cmdSelectDataSource.Width = intWidth

Me.cmdSelectRecipients.Height = 45
Me.cmdSelectRecipients.Width = 75

Me.cmdMergeDocument.Height = 45
Me.cmdMergeDocument.Width = 75


'protect document again
ThisDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
Password:="hi"

Exit_cmdMergeDocument_Click:
Exit Sub

Err_error_Click:
MsgBox Err.Description
Resume Exit_cmdMergeDocument_Click

End Sub

Thanks,


Peter Jamieson;416640 Wrote:
I tried something more like


Dim intHeight As Integer
Dim intWidth As Integer

' save the button dimensions

intHeight = Me.cmdSelectDataSource.Height
intWidth = Me.cmdSelectDataSource.Width

' do the merge
'

' restore the button dimensions

Me.cmdSelectDataSource.Height = intHeight
Me.cmdSelectDataSource.Width = intWidth--
--

It seems logically pretty much the same as yours, so
a. it is possible that mine wasn't working quite as I imagined. I'll

have anther look.
b. let's make sure we are using the same kind of buttons. Are you
using the standard "ActiveX" buttons (I think they are "Forms.2"
buttons)? I was actually testing with Word 2007 but I'll have a look
with Word 2003.

Peter Jamieson

http://tips.pjmsn.me.uk

rutica wrote:-
thanks for writing.

Peter, I tried Me.cmdMergeDocument.Width = 1 and it works!

The only weird thing is setting it back to normal on the main
document.
I want my height=45 and my width=117.

But for some reason, if my code lists the height first:
Me.cmdSelectDataSource.height =45
Me.cmdSelectDataSource.width=117
then both the height and the width are 117.

If i list the width first:
Me.cmdSelectDataSource.width=117
Me.cmdSelectDataSource.height=45
then both the height and the width are 45.

It's seems to only consider the last command and then apply that
value
to both height and width?

Here is my code that shows both the height and width as 45:

With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource

'make the buttons small
Me.cmdMergeDocument.Width = 1
Me.cmdSelectDataSource.Width = 1
Me.cmdSelectRecipients.Width = 1

.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord

End With
.Execute Pause:=False
End With

'now re-size the buttons again
Me.cmdSelectDataSource.Width = 117
Me.cmdSelectDataSource.Height = 45

Me.cmdSelectRecipients.Width = 117
Me.cmdSelectRecipients.Height = 45

Me.cmdMergeDocument.Width = 117
Me.cmdMergeDocument.Height = 45

How can i make the width=117 and the height=45?

Weird.

Peter Jamieson;416392 Wrote: -
Perhaps the best you can do is save their .Length and .Width
properties,

set them each to 1 prior to the merge, then set them back to the
saved

values.

Unless there is another approach that would fit your application,
e.g.

you insert macrobutton fields and connect them to appropriate VBA
functions, then remove the buttons altogether prior to merging, then
re-insert them after.

Peter Jamieson

http://tips.pjmsn.me.uk

rutica wrote:-
I have a Microsoft Word 2003 document that has mail merge fields with
Excel as its data source.

I created a few command buttons on my main form. One button allows
the
user to select the data source, one allows the user to select
recipients and the third Merges the data and creates a new document.

I would like those command buttons to *not* appear on the newly
created
documents.

Here is my code for the button that creates the new document:

Private Sub cmdMergeDocument_Click()
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True

Me.cmdSelectDataSource.Visible = False 'this doesn't work!
Me.cmdMergeDocument.Visible = False 'this doesn't work!
Me.cmdSelectRecipients.Visible = False 'this doesn't work!

With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With

'now show the buttons again on the main form
Me.cmdSelectDataSource.Visible = True 'this doesn't work!
Me.cmdMergeDocument.Visible = True 'this doesn't work!
Me.cmdSelectRecipients.Visible = True 'this doesn't work!
End Sub

I get 'Object doesn't support this property or method'.

I am able to do: cmdSelectDataSource.Enabled = False, but it's not
what
I need. I need the buttons invisible, not disabled.

Help!
Thanks,



--



-





--
rutica
  #7  
Old June 9th, 2009, 09:29 AM posted to microsoft.public.word.mailmerge.fields
Peter Jamieson
external usenet poster
 
Posts: 4,550
Default make buttons invisible

Hi, I tried it again with your code on Word 2003 and it is OK here.

If you open your main document and use Alt-F9 to look at the field codes
for the buttons, do you see

{ CONTROL Forms.CommandButton.1 \s }

or something else?

The few properties I changed experimentally (.Autosize, .Wordwrap) made
no difference. However, my test document is extremely simple (just the
three buttons in a Normal style paragraph, with a merge field to the
right or underneath. Again, simple tests (e.g. putting the buttons in a
table, or assigning an image to the button) made no difference, but I
wonder if there is something about the layout of your document that is
causing the difference?


Peter Jamieson

http://tips.pjmsn.me.uk

rutica wrote:
Peter, thank for writing again. I tried your way, but still got the
same result.

Something is forcing my code to be a square, I can't get the height and
width to be different. I am using the 'Control toolbox' to create a
command button. (In Office 2003: View, Toolbars, Control Toolbox). I
don't know if that is ActiveX...

I was able to get around my problem by having the height and width both
75. That suits my needs, this time at least.

Below is my code (to test, I only tried it with the cmdSelectDataSource
button). But the code doesn't work. Again, the height and width for
cmdSelectDataSource is the same even though the message box I created
for testing below shows a different height and width.

My AutoSize property for the 3 buttons is set to False. Could it
somehow to related to that? I tested by changing them to True, but no
change.

Private Sub cmdMergeDocument_Click()
On Error GoTo Err_error_Click
'merge document-step 3
Dim intHeight As Integer
Dim intWidth As Integer

intHeight = Me.cmdSelectDataSource.Height
intWidth = Me.cmdSelectDataSource.Width

'display the height and width for testing purposes
MsgBox "height is: " & intHeight & " and width is: " & intWidth

If MsgBox("Are you sure you want to create a new document(s)?",
vbOKCancel, "Create documents") = vbCancel Then
Exit Sub
End If

'first check if the document if protected. If so, unprotect it. Opening
the document triggers code to protect it (see the Document_Open()
event)
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect "hi"
End If


With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource

'make the buttons small
Me.cmdMergeDocument.Width = 1
Me.cmdSelectDataSource.Width = 1
Me.cmdSelectRecipients.Width = 1

.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord

End With
.Execute Pause:=False
End With

'now re-size the buttons again
Me.cmdSelectDataSource.Height = intHeight
Me.cmdSelectDataSource.Width = intWidth

Me.cmdSelectRecipients.Height = 45
Me.cmdSelectRecipients.Width = 75

Me.cmdMergeDocument.Height = 45
Me.cmdMergeDocument.Width = 75


'protect document again
ThisDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
Password:="hi"

Exit_cmdMergeDocument_Click:
Exit Sub

Err_error_Click:
MsgBox Err.Description
Resume Exit_cmdMergeDocument_Click

End Sub

Thanks,


Peter Jamieson;416640 Wrote:
I tried something more like


Dim intHeight As Integer
Dim intWidth As Integer

' save the button dimensions

intHeight = Me.cmdSelectDataSource.Height
intWidth = Me.cmdSelectDataSource.Width

' do the merge
'

' restore the button dimensions

Me.cmdSelectDataSource.Height = intHeight
Me.cmdSelectDataSource.Width = intWidth--
--

It seems logically pretty much the same as yours, so
a. it is possible that mine wasn't working quite as I imagined. I'll

have anther look.
b. let's make sure we are using the same kind of buttons. Are you
using the standard "ActiveX" buttons (I think they are "Forms.2"
buttons)? I was actually testing with Word 2007 but I'll have a look
with Word 2003.

Peter Jamieson

http://tips.pjmsn.me.uk

rutica wrote:-
thanks for writing.

Peter, I tried Me.cmdMergeDocument.Width = 1 and it works!

The only weird thing is setting it back to normal on the main
document.
I want my height=45 and my width=117.

But for some reason, if my code lists the height first:
Me.cmdSelectDataSource.height =45
Me.cmdSelectDataSource.width=117
then both the height and the width are 117.

If i list the width first:
Me.cmdSelectDataSource.width=117
Me.cmdSelectDataSource.height=45
then both the height and the width are 45.

It's seems to only consider the last command and then apply that
value
to both height and width?

Here is my code that shows both the height and width as 45:

With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource

'make the buttons small
Me.cmdMergeDocument.Width = 1
Me.cmdSelectDataSource.Width = 1
Me.cmdSelectRecipients.Width = 1

.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord

End With
.Execute Pause:=False
End With

'now re-size the buttons again
Me.cmdSelectDataSource.Width = 117
Me.cmdSelectDataSource.Height = 45

Me.cmdSelectRecipients.Width = 117
Me.cmdSelectRecipients.Height = 45

Me.cmdMergeDocument.Width = 117
Me.cmdMergeDocument.Height = 45

How can i make the width=117 and the height=45?

Weird.

Peter Jamieson;416392 Wrote: -
Perhaps the best you can do is save their .Length and .Width
properties,

set them each to 1 prior to the merge, then set them back to the
saved

values.

Unless there is another approach that would fit your application,
e.g.

you insert macrobutton fields and connect them to appropriate VBA
functions, then remove the buttons altogether prior to merging, then
re-insert them after.

Peter Jamieson

http://tips.pjmsn.me.uk

rutica wrote:-
I have a Microsoft Word 2003 document that has mail merge fields with
Excel as its data source.

I created a few command buttons on my main form. One button allows
the
user to select the data source, one allows the user to select
recipients and the third Merges the data and creates a new document.

I would like those command buttons to *not* appear on the newly
created
documents.

Here is my code for the button that creates the new document:

Private Sub cmdMergeDocument_Click()
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True

Me.cmdSelectDataSource.Visible = False 'this doesn't work!
Me.cmdMergeDocument.Visible = False 'this doesn't work!
Me.cmdSelectRecipients.Visible = False 'this doesn't work!

With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With

'now show the buttons again on the main form
Me.cmdSelectDataSource.Visible = True 'this doesn't work!
Me.cmdMergeDocument.Visible = True 'this doesn't work!
Me.cmdSelectRecipients.Visible = True 'this doesn't work!
End Sub

I get 'Object doesn't support this property or method'.

I am able to do: cmdSelectDataSource.Enabled = False, but it's not
what
I need. I need the buttons invisible, not disabled.

Help!
Thanks,



--



-





  #8  
Old June 9th, 2009, 04:17 PM posted to microsoft.public.word.mailmerge.fields
rutica[_10_]
external usenet poster
 
Posts: 1
Default make buttons invisible


I figured it out!

I had to uncheck 'lock aspect ratio'. I right clicked on my command
button and selected 'Format Control'. Then in the Size tab, I had to
uncheck 'lock aspect ratio'.

Thanks for writing back and trying to help!






Peter Jamieson;417271 Wrote:
Hi, I tried it again with your code on Word 2003 and it is OK here.

If you open your main document and use Alt-F9 to look at the field
codes
for the buttons, do you see

{ CONTROL Forms.CommandButton.1 \s }

or something else?

The few properties I changed experimentally (.Autosize, .Wordwrap) made

no difference. However, my test document is extremely simple (just the

three buttons in a Normal style paragraph, with a merge field to the
right or underneath. Again, simple tests (e.g. putting the buttons in a

table, or assigning an image to the button) made no difference, but I
wonder if there is something about the layout of your document that is

causing the difference?


Peter Jamieson

http://tips.pjmsn.me.uk

rutica wrote:-
Peter, thank for writing again. I tried your way, but still got the
same result.

Something is forcing my code to be a square, I can't get the height
and
width to be different. I am using the 'Control toolbox' to create a
command button. (In Office 2003: View, Toolbars, Control Toolbox). I
don't know if that is ActiveX...

I was able to get around my problem by having the height and width
both
75. That suits my needs, this time at least.

Below is my code (to test, I only tried it with the
cmdSelectDataSource
button). But the code doesn't work. Again, the height and width for
cmdSelectDataSource is the same even though the message box I created
for testing below shows a different height and width.

My AutoSize property for the 3 buttons is set to False. Could it
somehow to related to that? I tested by changing them to True, but no
change.

Private Sub cmdMergeDocument_Click()
On Error GoTo Err_error_Click
'merge document-step 3
Dim intHeight As Integer
Dim intWidth As Integer

intHeight = Me.cmdSelectDataSource.Height
intWidth = Me.cmdSelectDataSource.Width

'display the height and width for testing purposes
MsgBox "height is: " & intHeight & " and width is: " & intWidth

If MsgBox("Are you sure you want to create a new document(s)?",
vbOKCancel, "Create documents") = vbCancel Then
Exit Sub
End If

'first check if the document if protected. If so, unprotect it.
Opening
the document triggers code to protect it (see the Document_Open()
event)
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect "hi"
End If


With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource

'make the buttons small
Me.cmdMergeDocument.Width = 1
Me.cmdSelectDataSource.Width = 1
Me.cmdSelectRecipients.Width = 1

.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord

End With
.Execute Pause:=False
End With

'now re-size the buttons again
Me.cmdSelectDataSource.Height = intHeight
Me.cmdSelectDataSource.Width = intWidth

Me.cmdSelectRecipients.Height = 45
Me.cmdSelectRecipients.Width = 75

Me.cmdMergeDocument.Height = 45
Me.cmdMergeDocument.Width = 75


'protect document again
ThisDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
Password:="hi"

Exit_cmdMergeDocument_Click:
Exit Sub

Err_error_Click:
MsgBox Err.Description
Resume Exit_cmdMergeDocument_Click

End Sub

Thanks,


Peter Jamieson;416640 Wrote: -
I tried something more like


Dim intHeight As Integer
Dim intWidth As Integer

' save the button dimensions

intHeight = Me.cmdSelectDataSource.Height
intWidth = Me.cmdSelectDataSource.Width

' do the merge
'

' restore the button dimensions

Me.cmdSelectDataSource.Height = intHeight
Me.cmdSelectDataSource.Width = intWidth--
--

It seems logically pretty much the same as yours, so
a. it is possible that mine wasn't working quite as I imagined. I'll

have anther look.
b. let's make sure we are using the same kind of buttons. Are you
using the standard "ActiveX" buttons (I think they are "Forms.2"
buttons)? I was actually testing with Word 2007 but I'll have a look
with Word 2003.

Peter Jamieson

http://tips.pjmsn.me.uk

rutica wrote:-
thanks for writing.

Peter, I tried Me.cmdMergeDocument.Width = 1 and it works!

The only weird thing is setting it back to normal on the main
document.
I want my height=45 and my width=117.

But for some reason, if my code lists the height first:
Me.cmdSelectDataSource.height =45
Me.cmdSelectDataSource.width=117
then both the height and the width are 117.

If i list the width first:
Me.cmdSelectDataSource.width=117
Me.cmdSelectDataSource.height=45
then both the height and the width are 45.

It's seems to only consider the last command and then apply that
value
to both height and width?

Here is my code that shows both the height and width as 45:

With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource

'make the buttons small
Me.cmdMergeDocument.Width = 1
Me.cmdSelectDataSource.Width = 1
Me.cmdSelectRecipients.Width = 1

.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord

End With
.Execute Pause:=False
End With

'now re-size the buttons again
Me.cmdSelectDataSource.Width = 117
Me.cmdSelectDataSource.Height = 45

Me.cmdSelectRecipients.Width = 117
Me.cmdSelectRecipients.Height = 45

Me.cmdMergeDocument.Width = 117
Me.cmdMergeDocument.Height = 45

How can i make the width=117 and the height=45?

Weird.

Peter Jamieson;416392 Wrote: -
Perhaps the best you can do is save their .Length and .Width
properties,

set them each to 1 prior to the merge, then set them back to the
saved

values.

Unless there is another approach that would fit your application,
e.g.

you insert macrobutton fields and connect them to appropriate VBA
functions, then remove the buttons altogether prior to merging, then
re-insert them after.

Peter Jamieson

http://tips.pjmsn.me.uk

rutica wrote:-
I have a Microsoft Word 2003 document that has mail merge fields with
Excel as its data source.

I created a few command buttons on my main form. One button allows
the
user to select the data source, one allows the user to select
recipients and the third Merges the data and creates a new document.

I would like those command buttons to *not* appear on the newly
created
documents.

Here is my code for the button that creates the new document:

Private Sub cmdMergeDocument_Click()
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True

Me.cmdSelectDataSource.Visible = False 'this doesn't work!
Me.cmdMergeDocument.Visible = False 'this doesn't work!
Me.cmdSelectRecipients.Visible = False 'this doesn't work!

With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With

'now show the buttons again on the main form
Me.cmdSelectDataSource.Visible = True 'this doesn't work!
Me.cmdMergeDocument.Visible = True 'this doesn't work!
Me.cmdSelectRecipients.Visible = True 'this doesn't work!
End Sub

I get 'Object doesn't support this property or method'.

I am able to do: cmdSelectDataSource.Enabled = False, but it's not
what
I need. I need the buttons invisible, not disabled.

Help!
Thanks,



--



--



-





--
rutica
 




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:48 AM.


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