/ / HTML in Word konvertieren und Datei-Hyperlinks als Anhänge einbetten - HTML, VBA, MS-Word, MS-Office, Word-VBA

Konvertieren Sie HTML in Word und betten Sie Datei-Hyperlinks als Anhänge ein - HTML, VBA, MS-Word, MS-Office, Word-VBA

Ich habe einige HTML-Dateien, die ich mit Word öffneund als docx-Dateien speichern. Ich habe einige Makros, die ich ausführe, um die Verknüpfungen in den Grafiken zu unterbrechen, damit sie in die Dokumentdatei eingebettet werden, aber ich habe keine Möglichkeit gefunden, die Datei-Hyperlinks in eingebettete Anhänge zu konvertieren.

Wenn ich die htm-Dateien in Word öffne, sieht das so aus:

{HYPERLINK "C:\xxxx\test.zip o "test.zip"}

Der tatsächliche HTML-Code sieht beim Öffnen in Notepad im Grunde so aus

<a href="C:xxxxtest.zip" title="test.zip"><img src="/images/C:xxxx000002.gif" style="border-width: 0" /><span style="font-family: Arial; font-size: 9pt; color: #000000">test.zip</span></a>

Das GIF ist ein kleines Symbol für ZIP-Dateien.

Im Idealfall soll die End-docx-Datei so aussehen, als hätte ich sie gerade manuell in eine Datei gezogen und im Hauptteil des Dokuments angehängt.

Antworten:

0 für die Antwort № 1

Ich denke, der beste Weg wäre wahrscheinlich zu analysierendie HTM - Datei als Klartext, anstatt sie in Word zu öffnen, aber ich habe im Moment keine Zeit dafür. Dies könnte funktionieren, wenn der Windows - Standardspeicherort für das ZIP - Symbol verwendet wird.

Sub Macro2()

"Assume example structure like:
""{HYPERLINK "C:\xxxx\test.zip o "test.zip"}"

Dim htmLink As String
Dim fileName As String
Dim iconLabel As String

Dim v As Variant


"## Do you want to display the file icon?
showIcon = True

"## the htm "link" you need to change:
htmLink = "{HYPERLINK ""c:\users\david_zemens\desktop\1-8 test.zip o ""1.8 test.zip""}"


"## reformat the link:
" first split it by space (assumes no spaces in the filename...
v = Split(htmLink, """")

"v(1) is the location of the file;
" you can verify in the Locals window
fileName = Replace(v(1), Chr(34), vbNullString)
fileName = Replace(fileName, "\", "")
fileName = Replace(fileName, " o", vbNullString)
fileName = Trim(fileName)

"v(2) is the filename:
iconLabel = v(2)

"## Add to your document
" modify "Selection" to refer to any Word.Range, I think
Selection.InlineShapes.AddOLEObject ClassType:="Package", fileName:= _
fileName, LinkToFile:=False, _
DisplayAsIcon:=True, IconFileName:="C:Windowssystem32packager.dll", _
IconIndex:=0, iconLabel:=iconLabel


End Sub