Mam kilka plików HTML, które otwieram za pomocą programu Wordi zapisywanie jako pliki docx. Mam kilka makr, które uruchamiam, aby przerwać łącza na grafice, dzięki czemu są one osadzone w pliku doc, ale nie znalazłem żadnego sposobu, aby przekonwertować hiperłącza pliku na osadzone załączniki.
Kiedy otwieram pliki htm słowem, wygląda to tak:
{HYPERLINK "C:\xxxx\test.zip o "test.zip"}
Faktyczny kod html po otwarciu w Notatniku wygląda zasadniczo tak
<a href="C:xxxxtest.zip" title="test.zip"><img src="/images/C:xxxx 000002.gif" style="border-width: 0" /><span style="font-family: Arial; font-size: 9pt; color: #000000">test.zip</span></a>
Z .gif jest małą ikoną reprezentującą pliki zip.
Idealnie chciałbym, aby plik docx wyglądał tak, jakbym właśnie ręcznie przeciągnął plik i przyłączył go do treści dokumentu.
Odpowiedzi:
0 dla odpowiedzi № 1Myślę, że prawdopodobnie najlepszym sposobem byłoby przeanalizowanieplik HTM jako zwykły tekst, zamiast otwierać go w słowie, ale w tej chwili nie mam na to czasu.
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