PDA

View Full Version : Solved: Stuck on Combo Boxes



ABrown
05-01-2008, 12:26 AM
Hi, with the help of this forum I have successfully created two sets of combo boxes based on the styles in two different documents. The Combo Boxes sit side by side and list the styles in one document against the styles in another. I am now stuck!

I want to be able to take the style name from one box and swap it with the style in the document from its opposite box - ie.

Doc 1 Doc 2
Heading 1 Our New Style 1
Heading 2 Our New Style 2

"Change Button"

When I click the Change Button I want to be able to swap the styles in doc 1 with the styles in doc 2. I just don't know where to start - I appreciate that I have not made an attempt at any code - but all my attempts have failed miserable - I tried it using a case select, but wasn't sure where to start and it didn't work - can anyone suggest a starting point for this project.

Any help would be very much appreciated.

Regards.

Annette

burtburt
05-01-2008, 07:28 AM
From what you describe you are trying to do, I think the "Organizer" does this already.

Go To:
Tools>Templates and Add-Ins...
Then select the "Templates" tab
On the bottom left, click the "Organizer" Button

On the widow that launches select the "Stylese" tab
Here you can move styles between docs.

Is this what you want? If not. I would try recording a macro while doing this and looking at the code.

ABrown
05-01-2008, 08:16 AM
Thanks - will take a look - i actually need it coded and have used a macro recorder to record what I needed to do but when I put in the values from the combo box it doesn't work. I will go back to the drawing board and have a rethink.

Many thanks.

Annette

burtburt
05-01-2008, 09:02 AM
One more suggestion is to use a template with all the styles you want. Take the original and delete the text, then save as .dot. Then use that template to create new docs. The styles come over to the new doc. Don't know exactly what your doing but those are some things to think about. Good luck.

ABrown
05-01-2008, 09:03 AM
Many thanks!

fumei
05-01-2008, 09:16 AM
I am not quite following what you are trying to do.

Are you trying to port over the names, or the Styles themselves, but as a new name?

ABrown
05-12-2008, 03:29 AM
Apologies for delay but have been away for a week ! Now back to reality!

We have documents that come into our office with a set of styles in the document which we do not use. I have set up a form with a set of combo boxes which pickes all the styles from the current document. Another set of combo boxes contain the names of all the styles that we have in our template.

What I would like to be able to do - from each of the combo boxes in each of the sets is swap the styles - the comb boxes are names cb1 - cb20 and cbt1 - cbt20 - the result should be that the value in cb1 is swapped with the value in cbt1 which are all styles names within the document - thus with the click of a button I would like to move through each combo box named cb (whatever number) and swap the style in the document with the one in the cbt (whatever number)

i.e.

cb1 cbt1 (whatever is in cb1 will become style value of cbt1 in document)
cb2 cbt2 ditto etc. etc.
cb3 cbt3

I thought I might be able to loop through the first set of combo boxes but I am not sure how to group them?

Any help would really really be appreciated.

Thanks.

Annette

ABrown
05-12-2008, 04:16 AM
FYI - this is the code that I have so far for trying to change the first combo box, but it doesn't change the style in the document even though it does hold the value of the style??



st1 = Cmb1.Value
st2 = CmbT1.Value

ActiveDocument.CopyStylesFromTemplate _
Template:="H:\New Templates\Agreement Templates\Agreement1.dot"

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles(st1)
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles(st2)
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

MsgBox (st1)
MsgBox (st2)


Thanks again,

Annette

ABrown
05-16-2008, 03:34 AM
Managed to sort it all out thanks.

fumei
05-16-2008, 11:45 AM
Then let us know what and how.

ABrown
05-19-2008, 12:09 AM
It was a mistake I had made myself - I hadn't copied the styles from the template I needed for the document so when I initialized the form I copied the styles from my main template into the document and then it was just a simple line of code:

Selection.Style = ActiveDocument.Styles(cmb1.Value)

Was trying to over complicate things as usual.

Many thanks.

Annette