LINK field in Word - Pasting from Excel

  • Thread starter Thread starter rebecca.swift
  • Start date Start date
R

rebecca.swift

Hi

I have some cells in Excel that I wanted to paste into a Word document.

Steps I am going through are:

1. Copy cell in Excel
2. In Word, select Edit | Past Special | Paste Link - choosing HTML
format

The cell appears with an extra return (paragraph) and also a different
font size to the area I am pasting in.

I have been through all the field switches - and tried:

- adding \f 4 to format as per the Word document
- removing the \h
- adding \t

It seems very inconsistent and I am confused now. Does it have
something to do with the paragraph style?

I just want to be able to paste the number from Excel as a link and
format it the same as the Word document and the paragraph it is in.

Any ideas would be appreciated.

Bec
 
Add a \* charformat switch to the field and apply the required formatting to
the L of the Link

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

Thanks for that. Although there are going to be possibly 20 or 30
linked fields - will I have to do that with all of them?

Rebecca
 
The following macro will change all the mergeformat switches in a document
to charformat

Sub ChangeToCharFormat()
Dim oStory As Range
Dim oField As Field
Dim strChoice As String
Dim strReplace As String

Selection.HomeKey
ActiveWindow.View.ShowFieldCodes = True

strChoice = MsgBox("Replace Mergeformat switch with Charformat switch?" _
& vbCr & "Click 'No' to remove formatting switch completely", _
vbYesNoCancel, "Replace Formatting Switch")

If strChoice = 2 Then GoTo UserCancelled:

If strChoice = 6 Then
strReplace = " \* CHARFORMAT"
Else: strReplace = ""
End If

For Each oStory In ActiveDocument.StoryRanges
For Each oField In oStory.Fields
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " \* MERGEFORMAT"
.Replacement.Text = strReplace
.MatchWildcards = False
End With
Selection.Find.Execute replace:=wdReplaceAll
oField.Update
Next oField
Next oStory
With Selection
.WholeStory
.Fields.Update
.HomeKey
End With
UserCancelled:
ActiveWindow.View.ShowFieldCodes = False
End Sub

The following macro will change all the LINK fields only in a document from
Mergeformat to Charformat and add that switch if it is missing.

Sub ChangeSwitch()
ActiveDocument.ActiveWindow.View.ShowFieldCodes = True
Dim oRng As Range
Dim iFld As Integer
For iFld = ActiveDocument.Fields.Count To 1 Step -1
With ActiveDocument.Fields(iFld)
If .Type = wdFieldLink Then
If InStr(1, .Code, "MERGEFORMAT") <> 0 Then
.Code.Text = replace(.Code.Text, "MERGE", "CHAR")
End If
If InStr(1, .Code, "CHARFORMAT") = 0 Then
.Code.Text = .Code.Text & " \* CHARFORMAT "
End If
.Code.Select
.Update
End If
End With
Next iFld
ActiveDocument.ActiveWindow.View.ShowFieldCodes = False
End Sub

http://www.gmayor.com/installing_macro.htm
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

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

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

Back
Top