I am looking to automate a process at work, which has a step that requires me to go to a website, download data into a csv format, and then do the work and email out. I have written a set of macros that does most of this for me, however, I am having trouble understanding how to download data after navigating to the website (i see a few tutorials where the given website is already in excel format). Basically, you navigate to website, click drop-down menu, and pick export option.
I have the following script currently, and it gets me to the correct page. But I need to click on an "export" button and then an ".csv" format button once I get to this page. Does anyone have any advice, solutions or tutorials that I can look at?
'method to open chrome, collect Jira report and download it to folder
Sub getJiraReport()
Dim chromePath As String
chromePath = """C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"""
'loads the Jira Page with report
Shell (chromePath & " -url https://companyname.atlassian.net/issues/? filter=10600")
End Sub
Related
Hi I'm trying to create some sort of log system in an excel add-in im working on and so far the best way I can think of doing this is to collect event text together and then when excel attempts to close append this text to an online text file hosted on a team sharepoint. Not everyone will have the drive mapped locally so I want to ideally do this through the file URL and also not open the file as im adding the text.
So far I've managed to do this with a local file but cannot figure out how to do this with an online file through a URL. Here is what I have so far:
Sub testThis1(control As IRibbonControl)
Dim strFile_Path As String
strFile_Path = "C:/***" '<=a real address goes in here
Open strFile_Path For Append As #1
Write #1, "This Is my sample Text" & Now
Close #1
How can I go about taking this approach on a web hosted file rather than a local file? Thanks in advance for any help!
Okay so I have a program that is supposed to download a TXT file which ONLY contains a URL from my Dropbox, save it on my desktop, and then open the webbrowser like Process.Start(DownloadedFile).
My code looks like this:
Dim path As String = "C:\Users\" & SystemInformation.UserName & "\Desktop"
My.Computer.Network.DownloadFile("https://www.dropbox.com/s/uy9jpt1em3o6khp/download_location.txt?dl=1", path + "\" + "Download_Location" + ".txt")
Dim fileReader As String
fileReader = My.Computer.FileSystem.ReadAllText(path + "\Download_Location.txt")
Process.Start(fileReader)
Now my problem is that, the program DOES download my txt file and name it correctly. But even if I know that there is text in the text file, when the program downloads it and saves it on my Desktop named "Download_Location.txt", it is empty. The downloaded file doesn't conatin any text even if Im 100% sure that there should be a URL text.
And when my program reached the code where Process.Start(fileReader) it gives me an error:
You can not start the process because no file name is specified.
Thanks a lot! And sorry for my bad english.
When downloading files via a URL you are required to use a direct URL, due to that you download exactly the URL you specify. The reason you can download it from your web browser is because it first loads the page from the first link, then the page tells the browser to redirect to the actual file.
Direct links through DropBox are accessed via the dl.dropboxusercontent.com website, which is what you'll need to get the direct link to your file. The reason DropBox uses this system is probably because dropbox.com/s/... is yet a bit shorter than dl.dropboxusercontent.com/content_link/...
Having this said, switching your download URL from what you have now to: https://dl.dropboxusercontent.com/content_link/Uxdm1CQxQ50LBm5QejnkGLOIXJf8QL2Iui95XjhMUL2Wz4gjzBwiHttuA07RkbOl/file?dl=1 should work.
SharePoint 2010
Word 2010
Windows 7 Enterprise
I have a .docm file that lives in a SharePoint document library. When it is opened, a macro fires and prompts the user for a new file name and folder and then uses .SaveAs2 to save a copy of the file in the specified location as a .docx without the macro.
I cannot use SP content types with a proper .dotm as the template, since there are over 30 different file templates in the library. I have to use the .docm in a SharePoint library and then make sure that the user saves a copy of the file to their personal drive.
So I use some code in the open event. I let the user specify a folder and a file name. Then .SaveAs2 takes these parameters and saves the current file in the new path with the new name as a normal .docx file without macros. I'll spare you the details about how strFolder and strDoc are gathered. Rest assured that they exist. I have a debug.print with the full file name and it is correct.
With o
.SaveAs2 strFolder & strDoc & ".docx", wdFormatDocumentDefault
End With
The problem is that this code brings up a message saying that the file cannot be found.
Well, duh, I am trying to save the file in this location. Of course it does not exist. That's the point. (Note that the folder does exist.)
After the message box is closed, Word happily saves the file to the specified location.
Also, the message only pops up if the original file is opened in Read mode from SharePoint AND if the new file path is on a network drive.
The message does NOT pop up if
the file is opened in Edit mode (click the SharePoint file, select Edit in the next dialog), or if
the file is saved to a local drive (C:) or if
the file is opened from the File > Recent backstage dialog.
In the production system, the users will not have a choice of Edit or Read only. They will default to Read only. Also the users will not be able to save to a local C:\ drive, since the business system puts their profile and "My Documents" on a network drive (H:).
I have tried
saving the file with a different approach: using msoFileDialogSaveAs -- same message
suppressing the message with Application.DisplayAlert = False (I know but I was desperate) or wdAlertsNone. - Does not work. Message still shows
suppressing the message with Application.ScreenUpdating = False. Does not work. The message still shows.
suppressing the message with error handling On Error Resume Next or On Error Goto MyHandler but the message pops up without the error handlers being fired. The message has the blue "i" icon, so maybe it is not interpreted as an error, but as a piece of information.
How do I make the message go away?
Also, although this is not essential, it would be nice to know:
Why does Read or Edit mode matter when the file is saved to a new location?
Why does the new location of the file (network path or local path) matter when it is saved?
And why does the message come up when afterwards the file saves correctly?
After several futile attempts to change the way SharePoint serves the document in read only mode, I used the following approach to create a new Word doc, save it to the user's temp folder, copy the doc from the temp folder to the folder previously specified by the user. Now the document exists and using SaveAs does not trigger the error message.
Before the code below runs, the user has defined a file name (strDoc) and a folder for the document to be saved to.
' since we get an annoying message when trying to save to a network drive while
' in read only mode, we first create a new, empty file in the user's temp folder,
' then copy that empty file to the specified folder
' set the temp folder and full path
tempFolder = Environ("Temp")
tempPath = tempFolder & "\" & strDoc & ".docx"
' create a new document
Documents.Add DocumentType:=wdNewBlankDocument
ChangeFileOpenDirectory tempFolder
' save to temp folder and close
With ActiveDocument
.SaveAs2 tempPath, wdFormatDocumentDefault
.Close
End With
' copy from temp folder to previously defined destination
FileCopy tempPath, fullPath
' delete the temp file
KillFile = tempPath
' finally, save the contract over the empty file
With o
.SaveAs2 fullPath, wdFormatDocumentDefault
End With
Here's a shot in the dark based on some googling and similar experience:
http://blogs.technet.com/b/wordonenotesupport/archive/2009/02/07/word-2007-file-save-errors-an-error-is-displayed-when-attempting-to-save-a-word-document.aspx
The relevent bits:
"<path and file name>" cannot be found. Check your spelling, or try a different path.
<path and file name> is currently in use. Try again later.
Word cannot complete the save to due to a file permissions error.
You might see the aforementioned errors if Word 2007 is having a
conflict with antivirus software. Most of these conflicts have been
addressed by the antivirus software manufacturers, but you must
download and install updates or patches for the antivirus software
(not just new virus definitions) to resolve the issue. See the
software manufacturer's web site for possible updates and for
knowledge base articles concerning configuration issues.
...and then from McAfee describing a related issue:
https://kc.mcafee.com/corporate/index?page=content&id=KB75449
Most forum discussions I found implicate server-side realtime anti-virus scanning - something about the interplay of behavior between the saving mechanism of Office 2010 not playing nice with live, access-based file scanning.
Even if this doesn't solve your issue, hope it helps!
I have a dynamically generated PDF that I wish to download to the harddrive. The file download is started by the vb.net code:
WebBrowser1.Navigate("javascript:fnSubmitPDFForm('modalDivpdf')")
and I currently get the normal internet explorer 'File Download' window with the Open Save Cancel options. I would like to specifiy a folder and filename and automatically download the PDF. Is this possible?
Here is a better example of a link that induces the 'File Download' window. I'd like to automatically save the PDF:
WebBrowser1.Navigate("http://www2.hungryhorse.co.uk/index.php/download_file/view/838/71/")
Thanks
You can neither automatically download the file nor specify a path. You can however give a suggested filename:
context.Response.ContentType = "application/octet-stream"
context.Response.AddHeader("content-disposition", "attachment; filename=""" & "yourFilename.pdf & """")
context.Response.TransmitFile(actualFile)
Where yourFilename.pdf is the suggested filename and actualFile is the full path of the file to send.
I know this is an old thread, but I found it yesterday trying to solve the same problem. May sources say that it is not possible to do this, but it IS possible with a workaround. There are many reasons why this is needed; some wisecracks in other forums resort to "but why do you need it".
I must add that the solution below is not the most elegant, but perhaps it is the simplest, and it allowed me to solve the problem in a couple of hours.
There are two steps:
This will cause links to PDFs to automatically trigger the dialog asking if you want to save the file (with a default to "Cancel"). I did it by installing and then removing Adobe Reader. I know that there must be an elegant way around it by looking at some key in the registry, or by configuring the web browser, but I run out of time with this problem.
Send key strokes to the pop-up dialogs.
The code looks like:
Public Sub YourFunction()
'...
WebBrowser1.Navigate("https://... your URL")
Wait(2)
' Accept question to save
SendKeys.SendWait("{LEFT}")
Wait(0.5)
SendKeys.SendWait("{ENTER}")
Wait(0.5)
' Actually save the file
SendKeys.SendWait("{ENTER}")
Wait(0.5)
'...
End Sub
The function "Wait" is needed to allow time to the WebBrowser control to actually navigate to the target URL; this might be different in your case. The code is :
Public Sub Wait(ByVal seconds As Double)
Static start As Date
start = Now()
Do While Now() < start.AddSeconds(seconds)
System.Windows.Forms.Application.DoEvents()
Loop
End Sub
It works. I just downloaded 1,700 PDFs (for my own purpose, not going to explain it). It took a little bit of time, though.
I have an application that manages multiple magazine PDFs on the hard drive. I need to open the PDF files into a specific page. I am able to call vbscript from my own software so I am looking for some vbscript snippet to open a PDF with a specific page loaded. I am a mac developer doing cross platform software, windows is not my standard bread and butter.
From the Adobe docs, I checked that using system calls to open a URL like:
http://myserver/mypdf#page=3
works fine but trying to use similar URL with the dummy file protocol like:
file://path/to/mypdf#page=2
does not work. After figuring that, I decided that I should try some vbscript call to some COM or ActiveX or whatever they use these days on windows but I don't know how to do it.
Thanks for any help.
You could use the "page=..." parameter of Acrobat Reader, like this:
Sub OpenPdf(filename, page)
Set wshShell = WScript.CreateObject("WSCript.shell")
wshShell.Run """%ProgramFiles%\Adobe\Reader 9.0\Reader\AcroRd32.exe"" /A ""page=" & _
page & """ " & fileName
End Sub
OpenPdf "c:\temp\myfile.pdf", 20
Try to use AcroExch.AVPageView.Goto() Method
and avoid the path of adobe executable