From: Doug Robbins - Word MVP on
The f4 or f5 depends upon the formatting that you select when you insert the
Link. It is the \* Charformat switch that controls the font formatting and
hence colour.

--
Hope this helps,

Doug Robbins - Word MVP

Please reply only to the newsgroups unless you wish to obtain my services on
a paid professional basis.

"Anthony" <excelmodeling(a)gmail.com> wrote in message
news:e145e4a5-a641-4717-9723-c71181204950(a)w12g2000vbj.googlegroups.com...
> Thank you, Doug.
>
> I think the switch for \a \f4 should be \a \f5. I got the info from
> http://office.microsoft.com/en-us/word/HP051861701033.aspx.
>
> \f
> 4 Maintain the formatting of the source file, if the source file is an
> Excel workbook
> 5 Match the formatting of the destination document, if the source file
> is an Excel workbook
>
> I tried f5 and it works. I was using \a \f5 before, but it did not
> work. Then I used your method with \* Charformat and it worked.
> Thanks again!
>
> However, when I used only \a \f5 \* Charformat, after update, it
> created an un-need line break under each of the field. Later, I use
> \a \f 4 \r \* Charformat and the extra line break did not come up.
>
> The challege that I am having is that there are many files to be
> updated throght this VBA program and each files may contain up to
> thousands of different types of links. Right now, I am using Graham's
> VBA method (see below) to update the code. I replace "MERGEFORMAT"
> with "Charformat", "[space] \r [space]" with "[space] \r \a \f 5
> [space]", and "[space] \t [space]" with "[space] \r \a \f 5 [space]".
> There may be other varity of switches needed to be replace. I am
> trying to get an effective way to do this. If anyone has any idea,
> please let me know.
>
> Also, if I have duplicate switch codes in the fields, how would that
> impact the update? The reason I asked is that if there are both "\t"
> and "\r" in the field, after I run the replacement code, I will get a
> pair of "[space] \r \a \f 5 [space]".
>
> In addition, does anyone know why Graham use the For Loop in a
> reversed order (and not For i = 1 to ActiveDocument.Fields.Count)?
>
> (Graham's example was found on other thread. The code was kind of
> slow. I then discovered that it updates the whole document for every
> loop. After I move the .update out side of the loop, it works 100
> times faster.)
>
> Anthony
>
> -----------------------------------
> Graham's VBA method (with modfication)
> -----------------------------------
> For i = ActiveDocument.Fields.Count To 1 Step -1
> With ActiveDocument.Fields(i)
> If .Type = wdFieldTOC Then
> If InStr(1, .Code, "MERGEFORMAT") <> 0 Then
> .Code.Text = _
> Replace(.Code.Text, _
> "\* MERGEFORMAT", "")
> End If
> .Update
> End If
> End With
> Next i

From: Anthony on
Thanks again, Doug.

A side issue, how to close any instance of Excel opened? Include the
one hidden (but can be seen in Task Manager Process tab).

Anthony

From: Doug Robbins - Word MVP on
If you are talking about an instance of Excel opened by some code that you
are running, you should use the following method:

Dim xlApp As Object
Dim xlbook As Object
Dim Excelwasnotrunning As Boolean

On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If Err Then
Excelwasnotrunning = True
Set xlApp = CreateObject("Excel.Application")
End If
On Error GoTo ErrMsg
With xlApp
Set xlbook = .Workbooks.Open("Drive:\Path\Workbookname")
'Do what you will with xlbook
Set xlbook = Nothing
End With
If Excelwasnotrunning Then
xlApp.Quit
End If
Set xlApp = Nothing

If it is just some left over instance, just delete it form the list of
processes in the Task Manager. You will get a warning message, but if you
are not running Excel for anything at that point, you can ignore the warning
(at least I do).


--
Hope this helps,

Doug Robbins - Word MVP

Please reply only to the newsgroups unless you wish to obtain my services on
a paid professional basis.

"Anthony" <excelmodeling(a)gmail.com> wrote in message
news:9c00476e-793f-4ac7-9988-685e402206e3(a)36g2000yqu.googlegroups.com...
> Thanks again, Doug.
>
> A side issue, how to close any instance of Excel opened? Include the
> one hidden (but can be seen in Task Manager Process tab).
>
> Anthony
>

From: Anthony on
Doug, thanks again for your solution. However, I was trying to delete
a "left over" instance that was created by other process. I need to
do this programmatically. I am wondering if there is way to do that.

Anthony


From: Doug Robbins - Word MVP on
I doubt that it can be done using VBA. Really, the other process should be
modified so that it does not leave anything behind.

--
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

"Anthony" <excelmodeling(a)gmail.com> wrote in message
news:9a3e7632-bfb2-49cd-9d32-e960e6f633d9(a)v25g2000yqk.googlegroups.com...
> Doug, thanks again for your solution. However, I was trying to delete
> a "left over" instance that was created by other process. I need to
> do this programmatically. I am wondering if there is way to do that.
>
> Anthony
>
>