|
本帖最后由 VBA万岁 于 2015-11-26 11:51 编辑
在老师的代码基础上,写了一个批量上传活动工作表截图的代码:
Sub 批量上传截图至ExcelHome()
Const Uid As String = "......"
Const Hash As String = "......"
Dim Shp As Shape
Dim Msg, PicName, Boundary As String
Dim n%
Dim SendData
Msg = ActiveWorkbook.FullName & "-" & ActiveSheet.name & ":" & Chr(10)
For Each Shp In ActiveSheet.Shapes
n = n + 1
Shp.Select
Selection.name = "myPic"
Selection.Copy
ActiveSheet.Shapes("myPic").Delete
ActiveSheet.PasteSpecial Format:="图片 (JPEG)"
PicName = "P" & Format(Date, "yyyymmdd" & Format(n, "00"))
Msg = Msg & PicName & Chr(10)
Selection.CopyPicture
With ActiveSheet.ChartObjects.Add(0, 0, Selection.Width + 2, Selection.Height + 2).Chart
.ChartArea.Border.LineStyle = 0
.Paste
.Export ActiveWorkbook.Path & "\" & PicName & ".jpg", "JPG"
.Parent.Delete
End With
Selection.Delete
Boundary = GetBoundary()
SendData = GetUpLoadSendData(Boundary, ActiveWorkbook.Path & "\" & PicName & ".jpg", _
"Filename", PicName & ".jpg", _
"proid", "0", _
"hash", Hash, _
"uid", Uid, _
"title", PicName, _
"filetype", "rar", _
"Filedata", PicName & ".jpg", _
"Upload", "Submit Query")
With CreateObject("MSXML2.XMLHTTP")
.Open "POST", "http://club.excelhome.net/misc.php?mod=swfupload&fid=2&action=swfupload&operation=upload", False
.setRequestHeader "Content-Type", "multipart/form-data; boundary=" & Boundary
.Send SendData
'Debug.Print .responsetext
End With
Dim Fso As Object
Set Fso = CreateObject("Scripting.FileSystemObject")
Fso.DeleteFile (ActiveWorkbook.Path & "\" & PicName & ".jpg")
Next
MsgBox "图片:" & Msg & "上传完毕!", , "上传图片"
End Sub
|
|