本篇文章给大家谈谈vba怎么获取网页图片,以及vba保存网页图片对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、用excel vba编程的IE对象法 获取网页数据问题 急!!! 没分了 只求好心人相助 谢谢
- 2、vba 怎么读取系统剪贴板中的图片到image控件?
- 3、excel 用VBA 编写宏,调用图片问题?
- 4、怎么通过excel vba 提取多网页数据 http://www.etmoc.com/Firm/productmore.asp?page=1 (1-119页)
- 5、如何用vba抓取网页数据
- 6、做一个电子表格excel vba 实时获取网页数据
用excel vba编程的IE对象法 获取网页数据问题 急!!! 没分了 只求好心人相助 谢谢
可使用excel自带的数据导入功能,参考如下程序。
如果,从多个带有一定规律性的网页导入,可使用循环语句。
Sub 宏1()
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;", _
Destination:=Range("$A$1"))
.CommandType = 0
.Name = "detailPage.action?loanId=394578"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Rows("1:25").Select
Selection.Delete Shift:=xlUp
Rows("12:14").Select
Selection.Delete Shift:=xlUp
Rows("15:15").Select
ActiveWindow.SmallScroll Down:=69
Rows("15:90").Select
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=-33
End Sub
vba 怎么读取系统剪贴板中的图片到image控件?
VBA不能直接读取剪切板的内容,需要分两步,先将剪切板内容保存到JPG,再从JPG中读取图片到IMAGE控件。
代码如下:
Option Explicit
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Private Type GdiplusStartupInput
GdiplusVersion As Long
DebugEventCallback As Long
SuppressBackgroundThread As Long
SuppressExternalCodecs As Long
End Type
Private Type EncoderParameter
GUID As GUID
NumberOfValues As Long
type As Long
Value As Long
End Type
Private Type EncoderParameters
Count As Long
Parameter As EncoderParameter
End Type
Private Declare Sub keybd_event Lib "user32" _
(ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function GdiplusStartup Lib "GDIPlus" (token As Long, inputbuf As GdiplusStartupInput, ByVal outputbuf As Long) As Long
Private Declare Function GdiplusShutdown Lib "GDIPlus" (ByVal token As Long) As Long
Private Declare Function GdipCreateBitmapFromHBITMAP Lib "GDIPlus" (ByVal hbm As Long, ByVal hpal As Long, Bitmap As Long) As Long
Private Declare Function GdipDisposeImage Lib "GDIPlus" (ByVal Image As Long) As Long
Private Declare Function GdipSaveImageToFile Lib "GDIPlus" (ByVal Image As Long, ByVal filename As Long, clsidEncoder As GUID, encoderParams As Any) As Long
Private Declare Function CLSIDFromString Lib "ole32" (ByVal str As Long, id As GUID) As Long
'Private Declare Function GdipCreateBitmapFromFile Lib "GDIPlus" (ByVal filename As Long, Bitmap As Long) As Long
Private Declare Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Integer) As Long
Private Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Integer) As Long
Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long '剪贴板
Private Declare Function CloseClipboard Lib "user32" () As Long
Const CF_BITMAP = 2
Private Sub My_Screen_1()
Call keybd_event(vbKeySnapshot, 0, 0, 0)
DoEvents
End Sub
Private Sub My_Screen_2()
Call keybd_event(vbKeySnapshot, 1, 1, 1)
DoEvents
End Sub
Public Function Screen2JPG(ByVal filename As String, Optional ByVal quality As Byte = 80) As Boolean
Dim tSI As GdiplusStartupInput
Dim lRes As Long
Dim lGDIP As Long
Dim lBitmap As Long
Dim hBitmap As Long
'复制单元格区域图像
''''''Range.CopyPicture xlScreen, xlBitmap
My_Screen_2
'打开剪贴板
OpenClipboard 0
'获取剪贴板中bitmap数据的句柄
hBitmap = GetClipboardData(CF_BITMAP)
'关闭剪贴板
CloseClipboard
'初始化 GDI+
tSI.GdiplusVersion = 1
lRes = GdiplusStartup(lGDIP, tSI, 0)
If lRes = 0 Then
'从句柄创建 GDI+ 图像
lRes = GdipCreateBitmapFromHBITMAP(hBitmap, 0, lBitmap)
If lRes = 0 Then
Dim tJpgEncoder As GUID
Dim tParams As EncoderParameters
'初始化解码器的GUID标识
CLSIDFromString StrPtr("{557CF401-1A04-11D3-9A73-0000F81EF32E}"), tJpgEncoder
'设置解码器参数
tParams.Count = 1
With tParams.Parameter ' Quality
'得到Quality参数的GUID标识
CLSIDFromString StrPtr("{1D5BE4B5-FA4A-452D-9CDD-5DB35105E7EB}"), .GUID
.NumberOfValues = 1
.type = 4
.Value = VarPtr(quality)
End With
'保存图像
lRes = GdipSaveImageToFile(lBitmap, StrPtr(filename), tJpgEncoder, tParams)
'销毁GDI+图像
GdipDisposeImage lBitmap
End If
'销毁 GDI+
GdiplusShutdown lGDIP
End If
Screen2JPG = Not lRes
End Function
'最后,只要用载入图片即可。
Image.Picture = LoadPicture(filename)
excel 用VBA 编写宏,调用图片问题?
根据楼主的描述,个人觉得在VBA代码里边加入一个取消/允许触发连锁事件的语气就可以了,当双击C7单元格并回车之后,才会执行这些程序,引用改变的单元格无效(不会执行程序)。
示例如下:
Option Explicit
Private Sub Worksheet_Change(ByVal T As Range)
Application.EnableEvents = False '禁止触发连锁事件
On Error Resume Next
If T.Address = "$C$7" Then
Me.Image1.Picture = LoadPicture(ThisWorkbook.Path "\" T.Value ".jpg")
End If
If Err 0 Then MsgBox "此人没有照片", 16, "提示"
Application.EnableEvents = True '允许触发连锁事件
End Sub
怎么通过excel vba 提取多网页数据 http://www.etmoc.com/Firm/productmore.asp?page=1 (1-119页)
代码贴出来就失去了格式,没有可读性,所以贴个图出来。
这段代码用录制宏的方式产生,然后做了简单改动,可读性差了一点,但我实际操作过可以达到你的要求。我把代码全部贴到回答后面,你复制粘贴出去看看能不能用,不能用再想其他办法了。
Sub Macro1()
For n = 1 To 199
With ActiveSheet.QueryTables.Add(Connection:="URL;" n, Destination:=Range("$A$" ((n - 1) * 21 + 1)))
.Name = "productmore.asp?page=1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "1"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Next n
Columns("C:C").Select
Selection.TextToColumns Destination:=Range("C1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 2), TrailingMinusNumbers:=True
Columns("D:D").Select
Selection.TextToColumns Destination:=Range("D1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 2), TrailingMinusNumbers:=True
Columns("A:D").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$D$4179").AutoFilter Field:=1, Criteria1:="=品牌", _
Operator:=xlAnd
Rows("22:4159").Select
Selection.Delete Shift:=xlUp
ActiveSheet.Range("$A$1:$D$3981").AutoFilter Field:=1
End Sub
如何用vba抓取网页数据
Sub cc()
Cells.ClearContents
Set oDoc = CreateObject("htmlfile")
With CreateObject("WinHttp.WinHttpRequest.5.1")
.Open "GET",
"",
False
.Send
.WaitForResponse
oDoc.body.innerHTML = .responsetext
Set r = oDoc.All.tags("table")(7).Rows
For i = 0 To r.Length - 1
k = [a65536].End(3).Row
For j = 0 To r(i).Cells.Length - 1
Cells(k + 1, j + 1) = r(i).Cells(j).innerText
Next j
Next i
Set r = Nothing
End With
End Sub
做一个电子表格excel vba 实时获取网页数据
首先打开Excel 2007工作表,点击想要把数据导入的位置,然后在菜单栏找到第五项"数据“,点击,在“获取外部数据”项下找到“自网站”并点击。
这时弹出来”新建 Web 查询“对话框,可以在“地址”一栏键入要添加数据的网页的地址。
添加完成后,点击“转到(G)”,下面会出来要添加网页的内容和黄色箭头,单击要选择的表旁边的黄色箭头,可以看到点击后黄色箭头变成绿色的对号,这表示内容已经选中了,然后单击“导入(I)”。
弹出来”导入数据“对话框,设置完成点击“确定”。
Excel表中显示“正在获取数据……”。
数据获取完成,之前选中的网页内容全部导入了Excel工作表里。
vba怎么获取网页图片的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于vba保存网页图片、vba怎么获取网页图片的信息别忘了在本站进行查找喔。
2、本站永久网址:https://www.yuanmacun.com
3、本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行删除处理。
4、本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
5、本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
6、本站资源大多存储在云盘,如发现链接失效,请联系我们我们会第一时间更新。
源码村资源网 » vba怎么获取网页图片(vba保存网页图片)
1 评论