Excel 2013 code generates "Path not found" error in Excel 365 - excel

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?

Related

Run Macros in Excel file from a SharePoint site

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."

Workbook object ref' overwritten by second workbook object- Excel Office 365

Excel Office 365 Version 1902 (Build 11328.20420)
When two workbook objects are created and set to different excel files (using Application.Workbooks.Open) the second workbook object reference is somehow overwritten and points to the first file.
I encountered this problem whilst rewriting code in an existing spreadsheet application at work. The new code opens two excel files concurrently setting each excel workbook object to a file. The first time the method runs the expected behaviour is exhibited., the two objects point to their respective files. On the second and subsequent runs the first object seems to be overwritten by the second object and both objects point to the same file. I recreated this in a test method see below.
Option Explicit
Sub Main()
On Error GoTo err_handler
Dim Book1 As Workbook
Dim Book2 As Workbook
Set Book1 = Application.Workbooks.Open("C:\Test\Book1.xlsx")
Set Book2 = Application.Workbooks.Open("C:\Test\Book2.xlsx")
Debug.Print Book1.Name
Debug.Print Book2.Name
Exit Sub
err_handler:
MsgBox Err.Description
End Sub
The code produces this set of results
Run 1:
Book1.xlsx
Book2.xlsx
Run 2:
Book2.xlsx
Book2.xlsx
This issue is specific to Office 365. I tested the same code in Office 2016 and there is no issue.
Office 2016 results:
Run 1:
Book1.xlsx
Book2.xlsx
Run 2:
Book1.xlsx
Book2.xlsx
Is this a known issue that has been corrected in later versions of Office 365 or something new?
EDIT
It is yet to be explained why this behavior appears to be specific to Excel 365. The prior answer does not explain why this happens it merely states an observation that unpredictable behavior can occur when open workbooks are reopened. I did not see this same behavior when running the code using Excel 2016 (not Office 365)
Many thanks,
Simon.

Excel 2016 office 365 catastrophic failure

Start to get Excel catastrophic failure error
On OK opening debug windows, with auto creating each time new sheets, which is empty and strange structure
If I want something to do appears
So how to delete those sheets? or fix that error?
No background process started, file stored in xlsm and xlsb format do the same things. workbook and worksheets is not protected.
It looks like the file has been corrupted. It is unlikelly the problem can be easily reproduced from scratch.
Never the less you can script a vba macro to delete Sheets based on their names or not delete the sheets you want to keep.
sheetnametodelete= "sheetname"
With Application.Workbooks(ThisWorkbook.Name())
.Unprotect (yourpassword) ' required if protection is set
Dim wks As Worksheet
Set wks = .Sheets(sheetnametodelete)
If (Not wks Is Nothing) Then ' also check if wks belong to the defined blacklist
wks.Delete
End If
.Protect (yourpassword) ' required if protection is set
End With
Try to open the file from another computer in case your local Excel config is corrupted.
I had a similar problem (a fake workbook duplicated) in the past and decided to script a build process for my Excel vba based application.
See following links to learn more about module management.
https://www.rondebruin.nl/win/s9/win002.htm
http://www.cpearson.com/excel/vbe.aspx
you can also look at this post
Import a cls files and create a sheet
It provides code and comments from other contributors.
This is obviously not direct answer to your problem but if you intend to work on a consistent vba project I recommand to save your vba code out of your Excel file once in a while and setup a build of your Excel app.

Invalid forward reference, or reference to uncompiled type

I'm currently using a code to update a file with a loop running through multiple sheets. Up until now, the code ran smoothly. On today's run, I encountered "run-time error '-2147319767 (80028029)' Automation error, Invalid forward reference, or reference to uncompiled type."
The error occurs on the line Workbooks("Upload.xlsm").Worksheets(branchName).Range("C7").PasteSpecial Paste:=xlPasteValues and presents itself on the 6th iteration of the loop.
I used On Error Resume Next as a temporary measure to complete the run as it was imperative to have it done at that time.
Upon completion, 3 of the iterations had failed (sixth, seventh and tenth). The three had no correlation to one another (i.e. different copy sources, values, etc) but had other iterations with the exact same copy source/values which completed successfully.
Running another copy command at a later time onto these sheets resulted in the same error. I eventually had to delete and recreate the sheet to resolve the error.
' Uploads file update
fpath = Workbooks("TEG Rates.xlsm").Worksheets("Link List").Range("E3").Value
Workbooks.Open fpath & "Upload.xlsm"
For branchNo = 21 To 37
branchName = Workbooks("TEG Rates.xlsm").Worksheets("Link List").Range("A" & branchNo).Value
branchGroup = Workbooks("TEG Rates.xlsm").Worksheets("Link List").Range("B" & branchNo).Value
' Copy/Paste Buy & Sell
Workbooks("TEG Rates.xlsm").Worksheets(branchGroup).Range("D7:G111").Copy
Workbooks("Upload.xlsm").Worksheets(branchName).Range("C7").PasteSpecial Paste:=xlPasteValues
For no = 7 To 10
Workbooks("Upload.xlsm").Worksheets(branchName).Range("D" & no).Value = "=ROUND(100/C" & no & ",6)"
Next no
Workbooks("Upload.xlsm").Worksheets(branchName).Range("D14").Value = "=ROUND(100/C14,6)"
Workbooks("Upload.xlsm").Worksheets(branchName).Range("D15").Value = "=ROUND(10000/C15,4)"
Workbooks("Upload.xlsm").Worksheets(branchName).Range("D16").Value = "=ROUND(100/C16,6)"
Workbooks("Upload.xlsm").Worksheets(branchName).Range("D19").Value = "=ROUND(100/C19,6)"
Next branchNo
Workbooks("Upload.xlsm").Close SaveChanges:=True
Application.CutCopyMode = False
While currently I am able to operate this code, my concern is that my team will encounter this whilst I'm away. What could have caused this/what can I do to prevent this from occurring? I'd be willing to provide the files if required.
My friend and I had the same issue. I enabled the "AccessibilitycplAdmin 1.0 type admin" under Tools > References (within the VBA editor), that fixed the issue in both computers
I had the same issue with a macro today.
Noticed that the error popped up when selecting a sheet using Sheets(sheet_name_var).Select.
A workaround that I've found is:
- Make a copy of the sheet the macro was having problems with,
- Delete the original sheet,
- Rename the copy to the original name.
Hope this helps.
I was having the same error caused by an issue that was potentially related, and it was helpful to create a worksheet object rather than referencing a sheet within a workbook all in one step. So, instead of:
Workbooks("Upload.xlsm").Worksheets(branchName).Range("C7").PasteSpecial
You could instead try:
Dim xlWB as Excel.Workbook
Dim xlWS as Excel.Worksheet
Dim xlRange as Excel.Range
Set xlWB = Workbooks("Upload.xlsm")
Set xlWS = xlWB.Worksheets(branchname)
Set xlRange = xlWS.Range("C7")
xlRange.PasteSpecial Paste:=xlPasteValues
Sometimes it's beneficial to break up the steps, even though it is doing the same thing.
The only way I found to solve it was:
Change the property "Load To" for all query results in the damaged Sheet to "Only Create Connection".
Make a copy of the Sheet
Delete the damaged Sheet
Rename the just created Sheet to the name of the damaged one
Change all the query results to the new Sheet in the same original location
I hope this helps.
I had a very similar issue, I have several similar excel files, all with the same code. The code ran in all excels but one, with the same error:
"run-time error '-2147319767 (80028029)' Automation error, Invalid forward reference, or reference to uncompiled type."
I was able to solve the problem by saving the corrupt excel as .xlsx instead of .xlsm, closing all excel applications, reopen the .xlsx, add the code and save as .xlsm. Now it is working...
Exactly same thing happened to me. But with a little bit more serious consequences as my dashboard was already in production.
It was really shocking as code as running smoothly just 5 mins earlier.
Here's the changes that I made -
Conditional formatting
Pivot table updates - major formatting updates
I believe some weird combination of conditional formatting over pivot table might have caused this issue.
One peculiar symptom associated with this corrupted workbook/sheet as that I was unable to see any macro in the dialogue while I was trying to assign a macro to the button.
The dialogue box was empty ! not listing any macros from any module/form/worksheet.
Tried -
Removing pivot table
Resetting formatting
Removing conditional formatting
Restarting excel
Restarting system
None of the above worked !
Next solution, as suggested by Horacio, is to duplicate and delete the corrupted sheet.
This immediately solved the issue.
Similar problem - same error. The sheet is the results of a query "Load To" table. Followed the idea from https://stackoverflow.com/users/13737858/horacio-cano. Changed "Load to" from table to Connection only; deleted the sheet; changed "Load to" to new table; refreshed query. Macro runs without error.
I solved this by removing the reference to Microsoft Scripting Runtime in Tools>References selecting "Ok" and then re-adding it again.
(Not the exactly the same situation as posted by the OP, but the same error message:)
I got the same error message while trying to delete an ActiveX element in a UserForm.
Turns out that I still had (another) user form open as a modal window in the Excel app (which was in the background because I was trying to edit it the Visual Basic Editor).
Simply closing the user form solved the issue.
Not really an answer, but my 2 cents on the matter (a comment could not fit it :))
I found that the underlaying error comes from .NET:
Exception Source: mscorlib
Exception Type: System.Runtime.InteropServices.COMException
Exception Message: Invalid forward reference, or reference to uncompiled type. (Exception from HRESULT: 0x80028029 (TYPE_E_INVALIDSTATE))
Exception Target Site: InvokeDispMethod
With that, I found that this page:
https://developercommunity.visualstudio.com/t/live-code-analysis-causes-compiler-errors-in-code/599442
System.Runtime.InteropServices.COMException : A reference to the component 'MyProjectReference' already exists in the project.
at VSLangProj.References.AddProject(Project pProject)
So it appears the error is linked to some cached file(s) used internally and language stuff.
Now if you look here : What does 'Cor' stand for?
MSCorLib.dll officially became the acronym for Multilanguage Standard
Common Object Runtime Library.
If you finally add in the mix that I was manupulating files in Excel while changing the UI Language in settings just before I got a corrupted file with the same error that the OP mentions, I would guess the error definitely has some thing to do it!...

Error when setting workbook variable - 2147352565

I have a simple code that runs upon initialization of a userform that sets a few workbook and worksheet variables so they can be used easily throughout the rest of my modules, and the references can be easily changed in one place if the file moves. I recently migrated my workbooks from my desktop to a separate server/drive, and accordingly updated the file pathways; however, when I try to run the code now I immediately get the message:
"Run-time error '-2147352565 (8002000b)': Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus."
This error occurs on the line
Set ReportWkbk = Workbooks("N:\ rest of file pathway here\QuaRT_Template.xlsm")
Is there anything that can be happening on the server/drive that is causing this issue? If so, is there anything I can do to fix it? I do work with other excel workbooks saved in the same location that seem to have no issue being referenced, though their references are in the workbook itself, not through Visual Basic.
The Subscript Out of Range error occurs because the Excel workbook being referenced is not open (or opening) in the same instance of Excel. You can easily reproduce the error by creating two workbooks (name one WorkBook2.xlsx) and ensuring they open in separate instances of Excel. Then run this code:
Sub OpenWkbkNames()
Dim wbk As Workbook
For Each wbk In Workbooks
Debug.Print wbk.Name
Next
'Hmm. Workbook 2 is not listed, but lets activate it and see what happens.
Workbooks("workbook2.xlsx").Activate
End Sub
You could avoid the issue by looping through the names of the workbooks open in THIS instance of Excel to ensure its available.
I've been researching Run-time error '-2147352565 (8002000b)' and found this: https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.vsconstants.disp_e_badindex.aspx
Apparently, that is VS's way of saying Subscript Out of Range too. I suspect (but have no solid proof) that since the code worked locally but the issue appeared after the file was migrated to a shared drive that Windows is taking a long time to open the file so opens it in a new instance of Excel. Essentially, Excel gets impatient and decides to move on while Windows completes its task. I base this assumption on the detection logic that was added to Excel 2013 (https://blogs.office.com/2013/06/03/opening-workbooks-by-running-separate-instances-of-excel/).

Resources