Open multiple hyperlinks in one window using Internet Explorer - excel

I'm using the following code to open several Hyperlinks in multiple tabs from excel in one window:
Sub Open_Hyperlinks()
Range("C10:C17").Select
Dim hl as Hyperlink
On Error resume next
for Each hl in selection.Hyperlinks
hl.Follow
Next hl
End Sub
But I would like to include a specific instruction to open the hyperlinks using Internet Explorer and not the default browser setup in my terminal due to the fact that for administrator permissions I'm not able to change it.
Do you know how to include that instruction?

You could try by calling Internet Explorer directly:
Call Shell("C:\Program Files (x86)\Internet Explorer\iexplore.exe -url " & hl. Address ,vbMaximizedFocus)

Related

Set Google Chrome Window to a Variable

I'm trying to open a Google Chrome window, and continue to use that window to do many things. Which means I need to set it to a variable. Is there anyway to do this?
I have the following code to open the Google Chrome window and navigate to a URL, but I need to do more than that.
Sub Test()
Shell ("C:\Program Files (x86)\Google\Chrome\Application\Chrome.exe -url https://google.ca")
End Sub
I want to type in my username and password, hit the submit button to log in, and do other things. Is there a way I can reference the chrome window like I could in Internet Explorer? (by using Set IE = ...)
Let us know exactly what you are trying to do in google chrome from excel.
If you are trying to send key commands you can try to use:
Shell ("C:\Program Files (x86)\Google\Chrome\Application\Chrome.exe -url https://google.ca")
Application.Wait Now + 0.00003
Application.SendKeys "{Tab}", True
etc. etc. etc.
Hope this helps!

Opening Excel file from Sharepoint as Read-Write

I automatically open, edit, save and close several Excel workbooks from a Sharepoint location. The following code opens the workbooks (path loops through a list to hit each workbook name):
Workbooks.Open Filename:=path, ReadOnly:=False, Editable:=True
The files open in Read-Only mode, and the yellow dialogue option to Enable Editing does not appear.
I edit these workbooks manually and through a macro, but I am unable to save the files back onto the Sharepoint afterwards without saving as a new file.
I am using Excel 2013. This was working as intended about a year ago, but I believe there may have been updates to Office 365. I checked all of the Excel workbook security options, and nothing is set to open by default as Read-Only.
Is there any way to open the file in an editable mode through the macro, or at the very least allow the Enable Editing option to appear for each workbook?
I have been trying to fix the same problem for my files, and eventually did! So I felt that I could maybe let others know. And this old-ish thread came up near the top of my google search.
What fixed it for me was to edit the link.
from:
https://Company.sharepoint.com/:x:/r/teams/TeamNo/Shared%20Documents/Example/CoolFolder/TheBestExcelFile.xlsm
To:
https://Company.sharepoint.com/teams/TeamNo/Shared%20Documents/Example/CoolFolder/TheBestExcelFile.xlsm
Note that I only used replace to get rid of :x:/r/. I feel like I should have noticed this before but I didn't and no amount of meddling with the Workbook.Open parameters got me anywhere. It just seems odd that the default link copy thing gives you one with special commands in it. For our company most folders have spaces so the link has tons of "%20" in there so I simply read over the ":x:/r/".
Hope it helps someone.
Just for clarity, try this:
Sub Example()
'1.) Get filepath from somewhere
FilePath = Replace("https://Company.sharepoint.com/:x:/r/teams/TeamNo/Shared%20Documents/Example/CoolFolder/TheBestExcelFile.xlsm", ":x:/r/", "")
'2.) Open the file
Set StatisticsFile = Workbooks.Open(FileName:=FilePath, Password:="123")
'3.) Do things
'4.) Close the Sheet, save the changes. I simply like it this way, could be done in a single line.
StatisticsFile.Save
StatisticsFile.Close savechanges:=False
End Sub
I noticed this solution because I could still save the .xlsx file manually with the same name if I navigated to SaveAs. So if you guys can still do that after opening the file via macro, try a similar solution.
The interaction designed for Excel-OneDrive-SharePoint is new in 2016 apps and that version is a requisite to properly work.
The version 2013 may work by tweaking the OnDrive “Account” settings regarding Office co-authoring configuration which is specifically applied to Excel and Word
Right click the OneDrive icon in the taskbar to reach settings
Good luck!
I know your query was posted long ago but I have found the solution to remove the Read-Only blocker and update the excel document via Macro:
If you add "ActiveWorkbook.LockServerFile" after the code of opening the file, then it removes the Read-only and updates the excel as normal.

How to open an 'incognito' window from Microsoft Excel?

I've created links to the web in Excel but I need to find a solution how to open an 'incognito' window in my 'default' Chrome browser.
I found a way to accomplish this. Create a desktop shortcut. In that shortcut have it direct to the browser. I did it with Chrome, so mine looked like:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
Then after the link to the browser is done add the switch to open in Incognito (may differ for browser). For Chrome it is -incognito
You then add the link you want to open, placing it inside quotes.
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -incognito "http://yourlinkhere.com"
In Excel you will link to the shortcut. It will give you warning boxes but those are easy enough to close. If anyone knows how to make a macro to disable them for just this click then I would like to know.
Below code works
Sub OpenIncognito()
Shell ("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe -incognito -url https://google.com")
End Sub

Can I skip file validation when programmatically opening a workbook?

I have a roughly 100MB-large Excel file that I am opening with this code that runs when a UserForm button is pressed:
Public Sub SelectButton_Click()
fNameAndPath = Application.GetOpenFilename(Title:="Please Select a Report")
If fNameAndPath = False Then Exit Sub
End Sub
Because this file is so big, it takes a while to validate before opening, and this validation makes up about half the time my entire macro takes to complete (I'm working in Excel 2013 and this file is not opening from a network or shared drive). If I open the file manually, then I get the option to skip validation after three seconds of validating. The problem with this is that it opens the file in Protected View, where I can't work with it.
Using VBA, is there a way to "force skip" this time consuming validation while simultaneously avoiding Protected View?
When Excel is completely closed, this warning/guideline appears in the bottom left of the opening splash screen:
When Excel is already open, this warning/guideline appears in the bottom right:
So far there are two solutions that I've found to be useful for solving this problem, thanks to the comments above:
1. Disabling Office Validation for Excel files in the Registry settings for Windows:
I prefer to use early binding, so I would suggest in the VBA editor window, opening the Tools window, selecting 'References...', and then checking the box next to 'Windows Script Host Object Model', and clicking OK. This will enable IntelliSense as you are writing your VBA:
Dim wsh As New WshShell
wsh.RegWrite "HKCU\Software\Microsoft\Office\15.0\Excel\Security\FileValidate\DisableEditFromPV", 0, "REG_DWORD"
Set wsh = Nothing
This will work for Excel 2013. If you have a different version of Office or Excel, you will use something other than 15.0 in your file path.
However, this method has the glaring problem of removing validation of any Excel file on your computer, even those that might have malicious code in them or that might run from dangerous locations, such as your Temp or Downloads folder.
Additionally, writing to the Windows Registry might be disallowed depending on your current environment or permissions. For that reason, I recommend a different solution:
2. Setting the location of the Excel file to be a Trusted Location in Microsoft Excel:
It's possible to set a new Trusted Location in the Registry via VBA, but since this method is intended for use by those who can't access the registry, we won't get into that.
To add the file's location (let's say it's the "Excel Files" folder in C:\) as a Trusted Location, first click the File tab and then click Options at the bottom of the File Menu:
In the Excel Options window that opens up, click on Trust Center at the bottom of the side menu and then click the Trust Center Settings button that appears on the right:
Finally, click the Add new location... option and enter C:\Excel Files\ (or whatever your folder location is; you can even browse to it), and then click OK. You can also check the option to include subfolders if you want.

ActiveWorkbook.Followhyperlink

I'm currently working on an Excel program with VBA and I need to open a file. I have the code below, which all works fine except when a user opens a file a warning message appears stating that some files could contain viruses etc. This is fine, however if a user presses cancel so they decline the opening then VBA spits the dummy. Is there a way to avoid this? Thanks.
Public Sub openFile ()
Dim file As String
file = "c:\somefile"
ActiveWorkbook.FollowHyperlink Address:=file, NewWindow:=True
End Sub
By design, security is managed on the user's computer and is not to be overruled by a macro.
Have your users add the location of the file to their trusted locations so the file can be opened without being checked by the Trust Center (Excel Options -> Trust Center -> Trust Center Settings -> Add new location).
Unforetunately not, the problem I've found when using vba for excel is that it is an extension to a pre-existing user driven program so input requests are inevitable, they've caused me far too many headaches.
It could be possible to simulate a keylog to automatically hit enter and accept the warning but this solution would not be reliable and I'm not even sure possible in vba.

Resources