I have migrated some Excel files, which contain Macro, in SharePoint. I am trying to get the macro runs based on the files in Excel but I am getting the following error: "run-time error 76: Path not found".
When I have the files local, this code used to run perfectly:
Sub Proceso_diarioLB()
' PROCESO DIARIO MACRO
Application.Run "'LIBRO MACROS LB.xlsm'!PROFLOSTN"
Application.Run "'LIBRO MACROS LB.xlsm'!STOFCONDN"
Application.Run "'LIBRO MACROS LB.xlsm'!COPIASTOFCONDN"
End Sub
Sub PROFLOSTN()
'
' PROFLOSTN Macro
'
'
ChDir "S:\local\007repctrlbcocoa\DOWNLOADS\data"
Workbooks.OpenText Filename:="S:\local\007repctrlbcocoa\DOWNLOADS\data\PL.txt"
How can I change the path so that it will pick the file in the SharePoint list.
Any help will be much appreciated.
There are limitations to using web based excel versus desktop versions, and one of them is that macros do not work via web based excel (eg. Opening within Sharepoint).
See Microsoft support
"A workbook in this format can be opened but macros do not run in a
browser window."
Related
I have search on this site and beyond for an answer to these questions, and also trawled through a collection of VB/C# books I have on VB/VSTO. So far I've drawn a blank. I've posted the same question on a VB.NET facebook group, and if I get a solution, I'll post it here so it'll help others.
I am developing an application-level Add-In for Excel using VB.Net & VSTO.
Part of the functionality involves opening .xlsm (Excel macro-enabled) files.
I have three questions I hope you can help me with.
I want to open each xlsm file with macros enabled, but not launch
any Auto_Open macro in the xlsm file, or trigger the Workbook_Open
event. Is that possible?
The xlsm file may have it's own ribbon attached to the file. Is it
possible to inhibit the xlsm's ribbon from being added?
The xlsm file may have ActiveX controls that are connected to VBA
macros. If a VBA macro produces an error, is it possible to catch
the error in the .NET Add-In? The error may include "macro not
found"
For info, at present I disable macros using the code snippet below. Whilst that helps with item #1, it doesn't help with items #2 or #3 (in fact, disabling macros is the cause of item #3).
Currently when I open the xlsm file(s) I disable macros using the following code:
' WorkbookType is a string representing a keyword within the Excel filename
' xlApp is running instance of Excel
Dim xlApp = Marshal.GetActiveObject("Excel.Application")
aWorkbook = xlApp.ActiveWorkbook
aSheet = xlApp.ActiveSheet
' Save current macro security setting
Dim oldSecurity = xlApp.AutomationSecurity
' Disable macros
xlApp.AutomationSecurity =
Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable
' Find & open WorkbookType workbook files in ProjectFolder
Dim info As New DirectoryInfo(CurrentProjectFolder)
For Each fileItem As IO.FileInfo In info.GetFiles
If fileItem.Name.Contains("~") Then
' Ignore temporary files
ElseIf fileItem.Name.Contains(WorkbookType) AndAlso fileItem.Name.Contains(".xls") Then
xlApp.AskToUpdateLinks = False
Dim wb = xlApp.Workbooks.Open(CurrentProjectFolder & "\" & fileItem.Name, UpdateLinks:=False)
xlApp.AskToUpdateLinks = True
End If
Next
' Restore macro security setting
xlApp.AutomationSecurity = oldSecurity
The xlsm file may have ActiveX controls that are connected to VBA macros. If a VBA macro produces an error, is it possible to catch the error in the .NET Add-In? The error may include "macro not found"
COM add-ins (represented by VSTO add-ins) and VBA macros are entirely different entities. You can't handle VBA errors in COM add-ins, or the opposite. But you may react to the application events, see Object model (Excel) for the list of available events.
The xlsm file may have it's own ribbon attached to the file. Is it possible to inhibit the xlsm's ribbon from being added?
To prevent the custom ribbon UI from loading you need to edit the file by removing the ribbon XML customizations contained inside the Excel file. VBA doesn't deliver any UI customizations nowadays. You can use the Open XML SDK for editing open XML documents on the fly from VSTO add-ins without involving the host application or its object model.
I'm trying to open an excel file in SharePoint through a vba code in another local excel file. However, it gives me a Dialog Box and lets me save the file instead of directly opening in Excel.
Below is the code I used. Would be very grateful for your help. Thanks.
Dim wb AS Workbook
FilePath = "https://company.sharepoint.com/sites/Folder1/Folder2/Filename.xlsm"
Set wb = Workbooks.Open(Filename:=FilePath, UpdateLinks:=0)
I had this issue also. First, you have to fix something in the excel options. So, go to File > Options > Advanced > then scroll down until you see Link Handling > then select the box that says "Open Supported hyperlinks to Office in Office Desktop Apps". Next, I used the coding below to get the link to work. you just need to reply the part of the coding with you sites url sharepoint file. the only issue I came up with is that you have to run the coding below, wait for the file to completely load, and then you can run macros on this file.
Sub OPEN_YRLY()
'
' OPEN_YRLY Macro
'
'
Range("C1").Select
ActiveWorkbook.FollowHyperlink Address:="https://aramark365-my.sharepoint.com/:x:/r/personal/......", NewWindow:=False, AddHistory:=True
End Sub
Using Excel 2010 on Windows 7. I have a VBA macro that saves the first worksheet of an excel workbook (.xlsm) into a CSV file. This had mostly worked in the past. Recently, I get error messages per the picture below, which state "Run-time error '1004': Microsoft Excel cannot open or save any more documents because there is not enough available memory or disk space."
So a couple things:
A common suggested solution from my Google searching is to set the file's location as a Trusted Location. This did not work.
I have enough disk space. That can't be the issue.
I'm not sure exactly what is meant by "available memory," but if it in any way refers to the Physical Memory figure listed in Windows Task Manager, that figure is 75%. The ultimate CSV file itself tends to be about 1,500KB.
I am always able to save this worksheet as a CSV manually without encountering any error messages, but when I do it via this VBA macro, I get the error message.
Picture of error message
My excel VBA save-as-CSV macro:
Sub saveAsCSV()
Application.DisplayAlerts = False
ThisWorkbook.Sheets("Sheet1").Copy
ActiveWorkbook.SaveAs Filename:="dummyfilename.csv", FileFormat:=xlCSV, CreateBackup:=True
ActiveWorkbook.Close
Application.DisplayAlerts = True
End Sub
Try this, you don't have to use Copy or Activate. If your code is in the workbook that you want to save as a workbook you can use ThisWorkbook. Kudos to #Variatus for identifying need for a path.
ThisWorkbook.Sheets("Sheet1").SaveAs ThisWorkbook.Path & "/" & "dummyfilename" & ".csv", FileFormat:=6
I have VBA code from Excel 2013 that used to work.
ActiveWorkbook.Sheets("Template").Copy After:=ActiveWorkbook.Sheets(Sheets.Count)
I changed to a computer with Excel 365 installed.
I will get the errors:
Path not found: '\VBA3CD.tmp'
400
The VBA3CD.tmp filename will differ every time. I've already "enable all macros" in Excel's security settings.
I've tried different varieties of the same thing, for example:
Set wsTemplate = Sheets("Template")
wsTemplate.Copy After:=Sheets(Sheets.Count)
Getting the same "Path not found" error.
If you are really getting an error about being unable to do something with the file system from the single VBA command to copy a worksheet - which obviously doesn't touch the file system, it's all in-memory - then something about that worksheet is probably trying to run vba code.
I just checked and when one copies a worksheet, the copy runs the WORKSHEET_CALCULATE and WORKSHEET_ACTIVATE events. It may be that one of these events or another are running code that needs that path. You just have to check the VBA code for the sheet being copied - does it have any Worksheet_ subroutines?
I'm trying to create a VBA in Excel 2010 that takes info from another spreadsheet that I'm not allowed to alter and bring it over to the spreadsheet with my macro built in. Here's my code:
Sub BringUpWorkbook()
Workbooks("RITE 1624.xls").Activate
End Sub
I have several VBA books, have visited dozens of sites on the Internet, including those here at stackoverflow.com, and cannot find a reason why I'm receiving the run-time error. The workbook is already open, I've tried adding everything trailing the title, I've tried removing the .xls, I've even did all of the above with in a variable. Any ideas?
Make sure the extension is correct. If it's a excel-2010 file like you indicate, you may need to update your code to reflect the extension of your "RITE 1624" file (e.g. .xlsx for a 2010 Excel workbook, .xlsm for a 2010 Excel macro-enabled workbook, or whatever the extension is.
Sub BringUpWorkbook()
Workbooks("RITE 1624.xlsx").Activate
End Sub
EDIT:
To make sure you have the right name of the workbook, you can print the name of each workbook in an immediate window.
Open up the VBA editor, and then press Ctrl+G to open the Immediate Window (or do View > Immediate window). Then run the following Macro:
Sub OpenWkbkNames()
For Each Workbook In Workbooks
Debug.Print Workbook.Name
Next
End Sub
Note that this will give you the names of all the open workbooks in the same Excel instance as your macro. If your RITE 1624 file is in a separate Excel instance, then the instance that your macro is in will not be able to see that file (and it won't appear in the output of the OpenWkbkNames code above). The simplest way to resolve this is to open all of your necessary files from the Excel instance that contains your macro.
Sub BringUpWorkbook()
Workbooks.Open("RITE 1624.xls").Activate
End Sub