/ / Converter HTML em Word e incorporar hiperlinks de arquivos como anexos - html, vba, ms-word, ms-office, word-vba

Converta HTML para Word e incorpore hiperlinks de arquivos como anexos - html, vba, ms-word, ms-office, word-vba

Eu tenho alguns arquivos HTML que estou abrindo com o Worde salvando como arquivos docx. Tenho algumas macros que corro para quebrar os links nos gráficos para que sejam incorporados no arquivo doc, mas ainda não descobri como converter os hiperlinks do arquivo em anexos incorporados.

Quando abro os arquivos htm no word, fica assim:

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

O código html real quando aberto no bloco de notas se parece basicamente com este

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

Com o .gif sendo um pequeno ícone que representa arquivos zip.

Idealmente, quero que o arquivo docx final pareça ter arrastado manualmente um arquivo e anexado ao corpo do documento.

Respostas:

0 para resposta № 1

Eu acho que provavelmente a melhor maneira seria analisaro arquivo HTM como texto simples, em vez de abri-lo em palavras, mas não tenho tempo para fazer isso no momento. Isso pode funcionar, usando o local padrão do Windows para o ícone ZIP.

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