私はExcel vbaで作業しています。エクセルvbaを使ってhtmlに画像を挿入したいです。しかし、それは画像を表示しません。
PlyrName="Me"
PlyrPicLoc = "C:\EP\Player Image\asdf1234567894.jpg"
HTML = "<!DOCTYPE html>" & _
"<html>" & _
"<head>" & _
"<title>" & PlyrName & "'s Profile" & "</title>" & _
"</head>" & _
"<body>" & _
"<img src=" & PlyrPicLoc & " height='150' width='150'>" & _
"</body>" & _
"</html">
Set objIE = CreateObject("InternetExplorer.Application") With objIE
.Navigate "about:blank"
Do While .Busy: DoEvents: Loop
Do While .ReadyState <> 4: DoEvents: Loop
.Visible = True
.Document.Write HTML End With
Set objIE = Nothing
2013年8月22日更新
Web から取得した元の画像を使用する場合、または adobe/snip から作成した場合は機能しますが、問題は、その画像が元の画像からのみコピーされ、このコードを使用して EP\Player 画像フォルダーに保存される場合です。表示されていません。コピー時に私のコードに何か問題があるのでしょうか?
Private Sub cmdinsertpic_Click()
Dim fd As FileDialog
Dim objfl As Variant
Dim msg
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.ButtonName = "Select"
.AllowMultiSelect = False
.Filters.Add "Image Files", "*.jpg;*.gif;*.bmp", 1
.Title = "Choose Player's image"
.InitialView = msoFileDialogViewDetails
.Show
For Each objfl In .SelectedItems
FilNam = objfl
Image1.Picture = LoadPicture(objfl)
'Picturebox1.Image = Image.FromFile(OpenFileDalog.Filename)
Next objfl
On Error GoTo 0
End With
'THIS WILL COPY THE PICTURE TO EP\Player Image Folder
NameFile = Application.ThisWorkbook.Path & "\Player Image\" & Trim(txtnewplayername.Value & txtnewmc.Value) & ".gif"
Call SavePicture(Image1.Picture, NameFile)
Set fd = Nothing
End Sub
たとえば、元の画像をコピーしてasdf1234567894.gifという名前を付け、EP\Player Image Folder に保存します。
Private Sub LoadPic_Click()
Dim objIE As SHDocVw.InternetExplorer
PlyrPicLoc = "file:///C:/EP/Player%20Image/asdf1234567894.gif"
Const PlyrNames = "Me"
Dim FSObj As Scripting.FileSystemObject
Dim TStream As Scripting.TextStream
sPATH = "C:\EP\sample.html"
sURL = "C:/EP/sample.html"
shtml = "<body>" & _
"<title>" & PlyrNames & "'s Profile" & "</title>" & _
"<img src=" & Chr(34) & PlyrPicLoc & Chr(34) & " height='150' width='150'>" & _
"<body>" & _
"</body>" & _
"</html>"
Set FSObj = New Scripting.FileSystemObject
Set TStream = FSObj.CreateTextFile(sPATH, True)
TStream.WriteLine (shtml)
TStream.Close
Set objIE = CreateObject("InternetExplorer.Application")
With objIE
.Navigate sURL
Do While .Busy: DoEvents: Loop
Do While .ReadyState <> 4: DoEvents: Loop
.Visible = True
End With
Set objIE = Nothing
Set FSObj = Nothing
Set TStream = Nothing
End Sub