PDA

View Full Version : Copy Autotext Entries between PCs



lynnnow
06-30-2007, 03:40 AM
Hi,

I need to know if there is a simple and fast way to export the AutoText entries from my current PC to another PC. I've tried copying the Normal.dot file to my destination PC, but it doesn't work sometimes. Also, I've used the Organizer function to copy the autotext entries. Is there a simple code that can export the autotext entries to a Word document and then I run a macro from the exported file to insert these autotext entries into the current PC.

When I was in a previous company, there was code that was used for this purpose, but at that time I was not introduced to coding in VBA so didn't look at the code though I was fascinated by how it worked.

Any pointers in getting this done are appreciated.

Thanks in advance.

Lynnnow

mdmackillop
06-30-2007, 06:16 AM
This will export all autotects from the activedocument template to another template file. You could then modify it to export to the existing Normal.dot. I don't understand why transferring normal.dot did not work. Is there more than one on the Destination PC?

Sub ExportAutotext()
Dim atEntry As AutoTextEntry
Dim Dest As String
Dest = "C:\Templates\Exp1.dot"

For Each atEntry In _
ActiveDocument.AttachedTemplate.AutoTextEntries
Application.OrganizerCopy _
Source:=ActiveDocument.AttachedTemplate.FullName, _
Destination:=Dest, Name:=atEntry.Name, Object:=wdOrganizerObjectAutoText
Next atEntry

End Sub

lynnnow
06-30-2007, 06:28 AM
Hi,

Thanks for the reply. I'm at a loss to understand why the export didn't work. But i'll try your suggetion. However, this code takes the activedocument's ATs, but I need to export the normal.dot ATs, cos the activedocument already has ATs that will be available with the template that is picked up. What I need is the ATs I've created to be shipped out.

Can it be done like the ATs from my current PC are printed out on a blank document and I can then run a macro to pick up the ATs from this list and push it into the new Normal.dot? This is the code I was talking about that I had seen in my previous company. This file has a huge list of medical words that were pushed into the Normal.dot file

Regards,

Lynnnow

mdmackillop
06-30-2007, 07:08 AM
If you open a new blank document based on the Normal template then run the code, it will collect the Autotexts from Normal and export them to Exp1 or whatever.

fumei
07-03-2007, 01:50 PM
this code takes the activedocument's ATs, This is incorrect.

AutoText entries are NOT held in documents. They are in templates. So the code does NOT take the activedocument's ATs...it takes the ATs from the template attached to the activedocument.

lynnnow
07-03-2007, 10:54 PM
Hi Fumei,

I know ATs are not "held" in documents. I'm working on a distribution system wherein I have a list of AT that can be distributed to a team with just running a macro to push the entries into their normal.dot instead of them trying to work the Organizer and mess things up. This macro will just use the list of autotext and insert it into the normal.dot.

I've not been able to sit with the code and give my entire attention to it, but this is how far my design has come to be.


Sub fiddle()
Dim ABC As AutoCorrectEntry
Dim myTemplate As AutoTextEntries

Set myTemplate = ActiveDocument.AttachedTemplate.AutoTextEntries
For i = 1 To myTemplate.Count
Selection.TypeText myTemplate.Item(i) & vbCr
Next i

For Each ABC In AutoCorrect.Entries
Selection.TypeText (ABC.Name & vbTab & ABC.Value) & vbCr
Next ABC

End Sub


Now all that this code does, as you can already figure out is it extracts all the AT and ACs from the donor normal/attached template. I've been thinking of using a commandbutton on the "pusher" Word document, use the Split function to pick up these entries from the Word document, and push it into the recepient's normal.dot file. This way, any updates to the ATs/ACs can also be made without the end user needing to struggle on how to add/alter existing ATs/ACs.

Any guidance on how this can be done is very much appreciated.

Txs

lynnnow

mdmackillop
07-04-2007, 11:13 AM
I've not looked at autocorrect, but try this for AutoTexts

Option Explicit
'Copy autotext to document
Sub fiddle()
Dim ABC As AutoCorrectEntry
Dim myTemplate As AutoTextEntries
Dim i As Long
Set myTemplate = ActiveDocument.AttachedTemplate.AutoTextEntries
For i = 1 To myTemplate.Count
With ActiveDocument.Bookmarks
Selection.TypeText "***BM " & Format(i, "000 ") & myTemplate.Item(i).Name & vbCr
.Add Range:=Selection.Range, Name:="BM" & i
Call FillABookmark("BM" & i, myTemplate.Item(i))
Selection.TypeText vbCr
End With
Next i
End Sub

'Fill autotext to bookmark, yoinked from Gerry
Sub FillABookmark(strBM_Name As String, strBM_Text As String)
Dim bolWasProtected As Boolean
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
bolWasProtected = True
ActiveDocument.Unprotect
End If
On Error Resume Next
With Selection
.GoTo what:=wdGoToBookmark, Name:=strBM_Name
.Collapse Direction:=wdCollapseEnd
ActiveDocument.Bookmarks(strBM_Name).Range.Text = strBM_Text
.MoveEnd unit:=wdCharacter, Count:=Len(strBM_Text)
ActiveDocument.Bookmarks.Add Name:=strBM_Name, Range:=Selection.Range
.Collapse Direction:=wdCollapseEnd
End With
If bolWasProtected = True Then
ActiveDocument.Protect wdAllowOnlyFormFields, _
NoReset:=True, Password:=""
End If
End Sub



'Write autotexts form Document Text to Normal.dot
Sub WriteATtoNormal()
Dim rng As Range
Dim i As Long
Dim txt As String
Dim AT As String
For i = 1 To 100
Set rng = ActiveDocument.Content
txt = "BM " & Format(i, "000")
With rng.Find
.Text = txt
.Execute
End With
Set rng = rng.Paragraphs(1).Range
AT = Mid(rng, 12, Len(rng) - 12)
NormalTemplate.AutoTextEntries.Add Name:=AT, Range:=ActiveDocument.Bookmarks("BM" & i).Range
Next
End Sub

fumei
07-04-2007, 11:54 AM
Well, I have to say I don't like it, but then I do not keep Autotext in Normal.dot. And...
push it into the recepient's normal.dot file.goes against my personal philosophy regarding users.

Shrug...there ya go.

I try and keep Normal as (ummmm) "normal" as possible. So it has just about no code, or Autotext.

All my code, AND Autotext are in globals. But hey...whatever.

I am unclear about what precisely is the issue. You can load a global dynamically and once loaded its Autotext are available.Sub Document_Open()
AddIns.Add FileName:= _
"X:\CorporateCrap\GlobalStuff\TestX.dot" _
, Install:=True
End SubIf you send someone a document with the above in it AND (important of course) they have access to the given path...then badda bing badda boom, they have the Autotext in that template.

You want to release it after?Sub Document_Close()
AddIns( _
"X:\CorporateCrap\GlobalStuff\TestX.dot" _
).Delete
End SubThey close the document and the global is dumped.

That way, ONE file can be maintained with Autotext. True, this only works as long as everyone can get the folder location.

I am trying to really follow what you are trying to do. Please explain:
I've been thinking of using a commandbutton on the "pusher" Word document, use the Split function to pick up these entries from the Word document, and push it into the recepient's normal.dot file.

You say you know Autotext are not held in documents. OK. However, if you are sending a document, then, ummmmm, how are you going to get the AT?

Are you thinking about creating a document of text, with the text a listing of AT? Then the recipient runs a macro that takes the text listing of extracted AT, and creates REAL Autotext in their Normal?

Bleeeeech! But yes, it would work.

fumei
07-04-2007, 12:00 PM
I also want to add, if you are planning to send a text document (listing the Autotext entries), you may have issues with:

1. updates. If you made a small change to an existing Autotext and passed it AS TEXT in a document, with code to add it to their normal.dot, if you use the same name...the user MUST press Yes or No to accept it.

2. graphics. If your Autotext have any graphics...you may have a problem.

mdmackillop
07-04-2007, 12:51 PM
If you send someone a document with the above in it AND (important of course) they have access to the given path...then badda bing badda boom, they have the Autotext in that template.

Agreed. I would put it into the WorkGroup templates location, where access is already established.

MsgBox Options.DefaultFilePath(wdWorkgroupTemplatesPath)