Usuario
NECESITO GUARDAR UNA PAGINA WEB COMO PDF

Pregunta
-
Hola mucho gusto, le agradezco me ayuden con un tema, tengo un código, que abre Internet explorer, llena datos que me solicita para realizar una búsqueda, lo que necesito es poder guardar la pagina como archivo PDF con el mismo nombre del dato de la celda usado para la búsqueda.
Hasta el momento únicamente he llegado hasta habilitar la opción de guardar como PDF, lo que no consigo es ponerle el nombre al archivo y darle guardar.
Les dejo mi código, gracias.
Option Explicit
Sub ExtraerDatos()
Dim IE As Object
Dim c As Long, UltimaFila As Long
Dim Celda As Range
Dim nombre As String
Const OLECMDID_PRINT = 6
Const OLECMDEXECOPT_DONTPROMPTUSER = 2
Const PRINT_WAITFORCOMPLETION = 2
nombre = ("A2:A" & UltimaFila)
Application.ScreenUpdating = False
Set IE = CreateObject("InternetExplorer.Application")
Let UltimaFila = Cells(Rows.Count, 1).End(xlUp).Row
IE.navigate "http://192.168.1.76/frmPrincipal.aspx"
IE.Visible = True
For Each Celda In Range("A2:A" & UltimaFila)
Application.Wait (Now + TimeValue("0:00:03"))
With IE
.Document.getElementById("txtDato").Value = Celda.Value
.Document.getElementById("btnCon").Click
.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
End With
Next Celda
IE.Quit
Set IE = Nothing
Application.ScreenUpdating = True
MsgBox "Proceso finalizado"
End Sub
Todas las respuestas
-
-
-
Espero te sea de utilidad
Dim xmlHTTP: Set xmlHTTP = CreateObject("Microsoft.XMLHTTP") Dim sHTMLPage As String Const bGetAsAsync = False ' para esperar respuesta ' Hace la llamada a la web xmlHTTP.Open "GET", strURL, bGetAsAsync xmlHTTP.Send ' send it (to the web, wait for result) sHTMLPage = xmlHTTP.responseText ' (como TEXT) If InStr(sHTMLPage, "<html>") Then msgbox("No hay PDF para " & strName) Else Dim adoStream: Set adoStream = CreateObject("adodb.stream") Const adTypeBinary = 1 ' ado typelib constantes Const adModeReadWrite = 3 Const adSaveCreateOverwrite = 2 With adoStream ' setup and write the graphics file to local disk... .Type = adTypeBinary ' as BINARY .Mode = adModeReadWrite .Open '= Me.wbCertiPDF.LocationURL ' el stream .Write xmlHTTP.responseBody ' escribe los datos (como binary)... .SaveToFile FSO_BuildPath(m_strpathToExport, strName & ".pdf"), adSaveCreateOverwrite .Close ' the stream End With End If
-
Yo estaba buscando lo mismo, y así es como he dado con este post, es muy útil para ciertos artículos ofrecer la opción de guardar en PDF, sobre todo cuando se trata de guías o tutoriales.
Aún no he probado el código, lo haré a ver que tal va.
Gracias por la aportación :-)