I'm able to display a google static map in Excel.
Sheets("Sheet1").Range("a1").Parent.Pictures.Insert theURL
This works fine but once my URL is longer than 1650 characters I get an error message.
It's the same when I use a shape to display the map.
Sheets("Sheet1").Shapes("gMap").Fill.UserPicture theURL
Is there another way to display a google static map in Excel?
My URL I want to display could be <= 5000 characters. It's a map with a polyline.
There are URL examples:
URL with 1649 characters
https://maps.googleapis.com/maps/api/staticmap?size=600x600&path=enc%3Amym~h?g~uz`??e?a?q?a?k?c?u?e?s?i?}?m?{`?c?s?a?i?a?i?a?i?a?i?a?g?a?o?a?g?c?q?a?i?g?c`?a?i?m?w`?a?q?q?s`?c?i?s?u`?e?q?m?y`?e?q?o?}`?q?w`?a?g?o?w`?c?g?e?q?a?g?k?o`?o?y`?m?w`?q?w`?a?g?q?u`?a?g?i?y`?m?s`?a?g?k?y`?a?g?i?w`?a?g?e?{`??q?c?y`?g?w`?a?e?e?u?g?g`?m?}`?a?g?m?{`?o?y`?k?a`?i?a`?i?c`?o?s`?u?q`?i?y?o?}`?c?y?c?k`?a?o?k?{`?c?o?o?w`?a?g?m?w`?m?y`?a?g?m?g`?i?y?q?{`?c?o?e?u`?o?m`?a?g?e?c`?d?u?f?c?z?`?b`?b?``?b?f`?a?f??h?`?z??h`?d?|??z?c?f`?i?j??d`??d??z??p?c?d`?i?d??h`?c?h??d`?c?z?a?b??d`?c?~?i?v?k?h?c?b`?k?j?e?h??~?n?b`?c?d??d`?i?b`?u?f?u?`?o?e?u`?q?w`?q?w`?c?e?q?g`?o?y?k?k?}?y?w?g`?s?}?g?i?}?i`?e?e?u?g`?a?e?s?m`?i?c`?c?o?e?{?a?m??k?e?c`?e?a`?a?g?u?o`?a?g?a?e?m?i`?i?{???q?o`?k?w?e?m?m?m`?m?i`?u?m`?c?e?e?m?s?u`??q?i?y?y?k`?a?e?u?q`?q?w`?a?i?q?w`?m?w`?u?u`?s?s`?u?s`?c?g?s?q`?s?q`?e?k?m?m`?q?u`?c?e?o?c`?g?}?b?ca?c?{?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?l`?j?p`?n?r`?b?f?t?r`?d?n?f?v`?m?z?{?~?s?|?a`?|?a`?v?c?`?k?j?m?n?a`?z?c?b?a`?x?c`?|?c?b?a`?|?q?n?a`?z?e?b?y?x?{?~?`?d`?`?z?}?f`?i?d`??f??l`??r`?v?l`?t?p`?`?f?x?n`?t?~?x?d`?v?b`?j?t?`?b?j?p?h?j?b?b?z?``?v?``?h?j`??p`??f?j?z?|?b?v?a?h?b?v?r?z?m?``?w?b?c?~?{?f?e?b`?}?``?q?h?a?d`?w?v?d?
Both URLs work when you copy them to your browser.
Here is an example using #Omegastripes idea of downloading to a folder first. My function in the comments, which converted to tinyURL also worked but can't be posted. Downloading to a folder is more robust however.
Note:
If on 32-bit remove the word PtrSafe
Code:
Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" (ByVal pCaller As Long, _
ByVal szURL As String, ByVal szFileName As String, _
ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Private Sub DownloadPic()
Dim url As String
Dim fileLocation As String
url = "https://maps.googleapis.com/maps/api/staticmap?size=600x600&path="
url = url & "enc%3Amym~h?g~uz??e?a?q?a?k?c?u?e?s?i?}?m?{?c?s?a?i?a?i?a?i?a?i?a?g?a?o?a?g?c?q?a?i?g?c?a?i?m?w?a?q?q?s?c?i?s?u?e?q?m?y?e?q?o?}?q?w?a?g?o?w?c?g?e?q?a?g?k?o?o?y?m?w?q?w?a?g?q?u?a?g?i?y?m?s?a?g?k?y?a?g?i?w?a?g?e?{??q?c?y?g?w?a?e?e?u?g?g?m?}?a?g?m?{?o?y?k?a?i?a?i?c?o?s?u?q?i?y?o?}?c?y?c?k?a?o?k?{?c?o?o?w?a?g?m?w?m?y?a?g?m?g?i?y?q?{?c?o?e?u?o?m?a?g?e?c?d?u?f?c?z??b?b??b?f`?a?f??h?`?z??h`?d?|??z?c?f`?i?j??d`??d??z??p?c?d`?i?d??h`?c?h??d`?c?z?a?b??d`?c?~?i?v?k?h?c?b`?k?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?f?e?b?}?``?q?h?a?d?w?v?d?"
fileLocation = "C:\Users\User\Desktop\TestFolder\Test.png"
If URLDownloadToFile(0, url, fileLocation, 0, 0) = 0 Then
Debug.Print "downloaded"
ThisWorkbook.Worksheets("Sheet1").Range("A1").Parent.Pictures.Insert fileLocation
Kill fileLocation
Else
Debug.Print "failed"
End If
End Sub
Result:
Related
I am struggling to download full html code from below page. I was using URLDownloadToFileA and MSXML2.XMLHTTP60 methods and none of them downloads full code. Part of the webpage is missing - table on the bottom with "DEBTI...." in not included in the code. My aim is to get these "DEBTI..." strings and I want to avoid selenium if possible. None of below codes work for me, but when I just ctrl+s (save) page from the browser everything is correctly mentioned in the code. Any suggestions? Thanks!
Sub Get_Data()
Dim xmlhttp As New MSXML2.XMLHTTP60, myurl As String
myurl = "https://ec.europa.eu/taxation_customs/dds2/ebti/ebti_consultation.jsp?Lang=en&Lang=en&refcountry=&reference=&valstartdate1=&valstartdate=&valstartdateto1=&valstartdateto=&valenddate1=&valenddate=&valenddateto1=&valenddateto=&suppldate1=&suppldate=&nomenc=2309&nomencto=&keywordsearch1=&keywordsearch=&specialkeyword=&keywordmatchrule=OR&excludekeywordsearch1=&excludekeywordsearch=&excludespecialkeyword=&descript=&orderby=0&Expand=true&offset=1&viewVal=Thumbnail&isVisitedRef=false&allRecords=0&showProgressBar=true" 'replace with your URL
xmlhttp.Open "GET", myurl, False
xmlhttp.Send
Open "C:\Desktop\test.txt" For Output As #1
Print #1, (xmlhttp.responseText)
Close #1
End Sub
Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, _
ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Function DownloadFile(URL As String, LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then DownloadFile = True
End Function
Sub test()
DownloadFile "https://ec.europa.eu/taxation_customs/dds2/ebti/ebti_consultation.jsp?Lang=en&Lang=en&refcountry=&reference=&valstartdate1=&valstartdate=&valstartdateto1=&valstartdateto=&valenddate1=&valenddate=&valenddateto1=&valenddateto=&suppldate1=&suppldate=&nomenc=8418&nomencto=&keywordsearch1=&keywordsearch=&specialkeyword=&keywordmatchrule=OR&excludekeywordsearch1=&excludekeywordsearch=&excludespecialkeyword=&descript=&orderby=0&Expand=true&offset=1&viewVal=List&isVisitedRef=false&allRecords=0&showProgressBar=true", "C:\Desktop\abc.html"
End Sub
web:
https://ec.europa.eu/taxation_customs/dds2/ebti/ebti_consultation.jsp?Lang=en&Lang=en&refcountry=&reference=&valstartdate1=&valstartdate=&valstartdateto1=&valstartdateto=&valenddate1=&valenddate=&valenddateto1=&valenddateto=&suppldate1=&suppldate=&nomenc=8418&nomencto=&keywordsearch1=&keywordsearch=&specialkeyword=&keywordmatchrule=OR&excludekeywordsearch1=&excludekeywordsearch=&excludespecialkeyword=&descript=&orderby=0&Expand=true&offset=1&viewVal=List&isVisitedRef=false&allRecords=0&showProgressBar=true
I have a table of products where there is say a pdf for a specific products user manual. I'm storing the model name and it's file path in my products table (in Access). I've created a form in Access that allows the user to search by product name and it narrows down the number of files and shows the results from the search in a list box. However my biggest problem is opening the actual PDF. It opens the file, but I have to store the file path exactly how it is and the path of the files are long. Is there a way to open the PDF hyperlinks without using the Followhyperlink command? Or is there a way that I can show only the file name of the pdf in my list box rather than the entire path name? If I change the display text in my products table it doesn't open the hyperlink, I get an error. Any help would be greatly appreciated!
Application.FollowHyperLink() has problems with security, especially when opening files on a network drive. See e.g. here: http://blogannath.blogspot.de/2011/04/microsoft-access-tips-tricks-opening.html
A better method is the ShellExecute() API function.
Essentially it looks like this (trimmed from http://access.mvps.org/access/api/api0018.htm ):
' This code was originally written by Dev Ashish.
' http://access.mvps.org/access/api/api0018.htm
Private Declare Function apiShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" _
(ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) _
As Long
Public Const WIN_NORMAL = 1 'Open Normal
Private Const ERROR_SUCCESS = 32&
Public Function fHandleFile(stFile As String) As Boolean
Dim lRet As Long
lRet = apiShellExecute(hWndAccessApp(), "Open", stFile, vbNullString, vbNullString, WIN_NORMAL)
If lRet > ERROR_SUCCESS Then
' OK
fHandleFile = True
Else
Select Case lRet
' Handle various errors
End Select
fHandleFile = False
End If
End Function
Now for your listbox:
Set it to 2 columns, the first being the model name, the second the file path.
Set the column width of the second column to 0, so it will be invisible.
And in the doubleclick event, call fHandleFile with the second column (file path):
Private Sub lstManuals_DblClick(Cancel As Integer)
Call fHandleFile(Me.lstManuals.Column(1))
End Sub
I want to be able to download images by using multiple image urls on vba. This is the code I have right now, and everytime I try download, it fails (It reads "Files not Found!"). Any help will be appreciated!!!
Option Explicit
Private Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, _
ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Private Sub Image()
Dim i As Long
Dim url As String
Dim done As Long
Worksheets("Sheet1").Activate
For i = 1 To 4
url = Sheet1.Range("A" & i).Text
done = URLDownloadToFile(0, url, "C:\Users\Public\Pictures\", 0, 0)
Next
'Test.
If done = 0 Then
MsgBox "Files have been downloaded!"
Else
MsgBox "Files not Found!"
End If
End Sub
I have got this code to work by doing two simple things:
Make sure you have http:// included in your urls, without the http URLDownloadToFile fails to download the file.
The usage of the URLDownloadToFile function is expecting a filename rather than a path name for the downloaded file. A quick and dirty fix is to do the following:
done = URLDownloadToFile(0, url, "C:\Users\Public\Pictures\pic" & i & ".gif", 0, 0)
which assigns a name to each file using i.
A better solution would parse the filename from the url and save using this filename.
Other than that the code worked fine for me.
I am trying to read a text file on a website using a PC that appears to be behind a proxy server. Originally I had 407 errors but then I added;
<system.net>
<defaultProxy useDefaultCredentials="true">
<proxy usesystemdefault="True" />
</defaultProxy>
</system.net>
to the app.config and now I get "Unable to connect to the remote server".
My code is:
' Make a WebClient.
myWebClient = New System.Net.WebClient
' Get the indicated URI.
Dim response As Stream = myWebClient.OpenRead("mySite/myfile.txt")
' Read the result.
Dim objreader As New IO.StreamReader(response)
If I enter "mySite/myfile.txt" into a browser from the same PC the website file is displayed on the screen.
Do I have a code error or is there a way my app can get around this?
I have solved the problem by reverting to the VB5 version which uses API calls to download the text file before reading it.
Thanks Randy Birch.
'//API to download file
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" _
(ByVal pCaller As Integer, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Integer, ByVal lpfnCB As Integer) As Integer
Private Declare Function DeleteUrlCacheEntry Lib "Wininet.dll" Alias "DeleteUrlCacheEntryA" (ByVal lpszUrlName As String) As Integer
Private Const ERROR_SUCCESS As Integer = 0
Private Const BINDF_GETNEWESTVERSION As Integer = &H10
'//
Private Function DownloadFileAPI(ByRef sSourceUrl As String, ByRef sLocalFile As String) As Boolean
'http://vbnet.mvps.org/index.html?code/internet/urldownloadtofile.htm
'http://vbnet.mvps.org/index.html?code/internet/urldownloadtofilenocache.htm
Call DeleteUrlCacheEntry(sSourceUrl)
'Download the file. BINDF_GETNEWESTVERSION forces
'the API to download from the specified source.
'Passing 0& as dwReserved causes the locally-cached
'copy to be downloaded, if available. If the API
'returns ERROR_SUCCESS (0), DownloadFile returns True.
DownloadFileAPI = URLDownloadToFile(0, sSourceUrl, sLocalFile, BINDF_GETNEWESTVERSION, 0) = ERROR_SUCCESS
End Function
and in the code;
Dim retbol As Boolean
Dim URL As String = "mySite/myFiletodownload"
fsavename = "mysavefile" 'path\filename to save downloaded file to.
Try
'This should return true or false so might not trigger an exception
retbol = DownloadFileAPI(URL, fsavename)
'etc
In an already open word document select all text
copy selected text to clipboard
check default browser open at correct web address
if not open default browser at web address "http://thisaddress.com"
give focus to browser
paste clipboard text into input box called "input1"
or some other way to get MSword document contents to a web page input?
Currently the workflow involves a secretary logging in to the website, then filling out a web form, switching to their open MS Word document, selecting all, copying the WP document, then back to the web form and pasting into an input box, then hitting submit. What I want to do ideally have a button in MS word which opens the browser to the correct web page then copies and pastes the document into the correct input box on the page (in fact it will be the only textarea form field).
The MS Word VBA code is:
Option Explicit
Enum W32_Window_State
Show_Normal = 1
Show_Minimized = 2
Show_Maximized = 3
Show_Min_No_Active = 7
Show_Default = 10
End Enum
Private Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" (ByVal hWnd As Long, _
ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Function OpenURL(URL As String, WindowState As W32_Window_State) As Boolean
' Opens passed URL with default application, or Error Code (<32) upon error
Dim lngHWnd As Long
Dim lngReturn As Long
lngReturn = ShellExecute(lngHWnd, "open", URL, vbNullString, _
vbNullString, WindowState)
OpenURL = (lngReturn > 32)
End Function
Sub TestMacro()
Application.ActiveDocument.Select
Selection.Copy
OpenURL "http://localhost:8500/index.cfm?wordContent=" & Selection, W32_Window_State.Show_Maximized
End Sub
and in the coldfusion handling form
<html>
<head>
</head>
<body>
<form id="form1">
<Textarea ID="txtArea" rows=6><cfoutput>#url.wordContent#</cfoutput></textarea>
</form>
</body>
</html>
Just would like to work out how to not open a new browser window if one is already open.
In case you can modify the web-application, you may do the following:
MS-Word: Copy content to clipboard.
MS-Word: Open Url as "http://thisaddress.com/SomePage?pasteClipboard=true"
SomePage: if query-string param pasteClipboard == true, then add a javascript function to get the clipboard data into your form field.
Update:
In your macro you simply call Selection.Copy, and to open the URL using default browser check this link http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_23225744.html
Using the code from the previous link, I made a test macro as :
Sub TestMacro()
Application.ActiveDocument.Select
Selection.Copy
OpenURL "http://thisaddress.com/SomePage?pasteClipboard=true", W32_Window_State.Show_Maximized
End Sub
I hope this was helpful.
Update 2:
Just use W32_Window_State.Show_Default, Here is the full macro:
Option Explicit
Enum W32_Window_State
Show_Normal = 1
Show_Minimized = 2
Show_Maximized = 3
Show_Min_No_Active = 7
Show_Default = 10
End Enum
Private Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" (ByVal hWnd As Long, _
ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Function OpenURL(URL As String, WindowState As W32_Window_State) As Boolean
' Opens passed URL with default application, or Error Code (<32) upon error
Dim lngHWnd As Long
Dim lngReturn As Long
lngReturn = ShellExecute(lngHWnd, "open", URL, vbNullString, _
vbNullString, WindowState)
OpenURL = (lngReturn > 32)
End Function
Sub TestMacro()
Application.ActiveDocument.Select
Selection.Copy
OpenURL "http://thisaddress.com/SomePage?pasteClipboard=true", W32_Window_State.Show_Default
End Sub
Another option is to look into controlling Internet Explorer from inside Word using a control.
Here is an example.
Note, this will only work with IE (unless there are dll versions of Firefox etc.)