I am using following VBA code in Excel 2010 in a button click event:
Dim objExcel as Object
Set objExcel - New Excel.Application
and used that instance objExcel in subsequent code.
This code is very simple and working in most of the computers I have tested including my computer. Whereas in some computers, that instance is not creating. objExcel is Nothing after the line is executed. So after the line of code is run, objExcel is Nothing. That is why subsequent codes are failing to execute.
I also tried following code:
Set objExcel=CreateObject("Excel.Application")
This also has same problem.
All machines have MS Office 2010 installed.
Problem is not due to large number of Excel instances Problematic computers cannot run the code even once.
Should I check or register any component which may cause the problem?
Related
I need to run automatically an excel macro that PDFs a monthly report and then saves and closes the excel file. My proposed solution is that using Windows Task Scheduler it runs a windows batch print file that runs a VBScript which then runs the excel file. The excel file when it is open then runs a macro that PDFs what I need. All of this I have tested many times locally on my PC and all of it works fine. Now this all needs to run on a remote desktop that is a virtual machine. This is where the issue happens. Everything runs fine up until it opens the excel file, the excel file opens in the background and its icon on the task bar flashes orange, because of this nothing else happens. The macro breaks and does not print, it doesn't even start in the first place. Is there any ideas on how to fix this? Here is the coding for the VBScript that opens the excel file.
Dim args, objExcel, openExcel
Set args = wScript.Arguments
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open args(0)
objExcel.Visible = True
objExcel.Run "ReportPrint"
objExcel.ActiveWorkbook.Save
objExcel.ActiveWorkbook.Close(0)
objExcel.Quit
I am trying to import data from an Excel sheet into Word.
But I am failing pretty quickly. Word gets stuck right at the beginning.
My code is a simple as that:
Sub ImportDataFromExcel()
Dim XLapp As Excel.Application
Set XLapp = New Excel.Application
End Sub
Here is what happens:
Excel opens up.
But Word freezes immediately. I have to force quit Word.
Word would not get to any further line of code I had included. It stops at „Set XLapp = New Excel.Application“.
I tried a couple of things:
I wrote similar code to open PowerPoint. That worked.
I wrote similar code into PowerPoint, to open Word from there. That worked.
I wrote the same code, that I posted here, into PowerPoint, to open Excel. That failed the same way!
And I also tried on a different Mac. Also there, same thing: Word freezes, when calling on Excel.
I am using Office 365 with Word and Excel for Mac, Version 16.24.
As macro-reference in VBA I use the „Microsoft Excel 16.0 Object Library“.
I am running MacOS Mojave (10.14.3) on my Mac.
Can anyone please help me?
I have no experience with this issue on Mac Os, but maybe rewriting the same code in a different way, will work. Try this:
Dim XLapp As New Excel.Application
Hope this helps.
Try this please
Sub ImportDataFromExcel()
Dim XLapp As Object
Set XLapp = CreateObject("Excel.Application")
End Sub
Maybe MAC do not recoginized the excel library
I have a windows application written in vb.NET that pulls details from a big excel workbook and uses them to create site specific documents, depending on what site a user of the application has been assigned. The application then opens up the excel workbook it creates, and populates certain cells with the desired information, before opening a word document it has created to do similar.
The application was working perfectly for all users, but has recently stopped working for a user with Windows 8.1 and 32-bit Excel 2013. The application opens up the master excel workbook and pulls all necessary information from it, however when it tries to open the excel workbook it has created, it cannot proceed any further and eventually throws the following error:
The remote procedure call failed. (Exception from HRESULT: 0X800706BE).
The following is the code that opens up the master workbook, closes it, then copies the workbook template, renames it and finally opens it.
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
Dim excelApp As Excel.Application = Nothing
Dim excelWB As Excel.Workbook = Nothing
Dim excelWS As Excel.Worksheet = Nothing
Dim fso As Scripting.FileSystemObject
Dim MasterLogLoc As String 'Path to the master workbook is stored in this string
Dim SiteTempLoc As String 'Path to the workbook template
Dim SiteWbLoc As String 'Path to the newly created wb
excelApp = New Excel.Application
excelWB = excelApp.Workbooks.Open(Filename:=MasterLogLoc, [ReadOnly]:=True, UpdateLinks:=False)
excelApp.Visible = False
excelWS = excelWB.Worksheets("Master")
excelWS.Select()
'Whatever details that are needed are grabbed
excelWB.Close(SaveChanges:=False)
excelApp.Quit()
excelApp = Nothing
excelWB = Nothing
'Next the template is copied and the newly created workbook is opened
fso = New Scripting.FileSystemObject
fso.CopyFile(Source:=SiteTempLoc, Destination:=SiteWbLoc)
fso = Nothing
'The application times out at the next part
excelApp = New Excel.Application
excelWB = excelApp.Workbooks.Open(SiteWbLoc)
excelApp.Visible = False
'The application times out at the above part
'Whatever needs to be done to the worksheet is completed
excelWB.Save()
excelWB.Close()
excelApp.Quit()
End Class
My computer is Windows 7, with Excel 2010 64-bit, and the application still works perfectly, it also still works perfectly on another Windows 7 computer.
The first time the user got this error, I got them to manually open up the workbook template, which showed that they did not have the file as a trusted document for their PC. After fixing this, they ran the application successfully but the next day the error appeared again, even though the workbook was now a trusted document.
The fact that the application opens up an already existing workbook successfully, but cannot open the workbook created on that PC, appears to be the main sign of the problem, however I am unsure where to proceed to next for troubleshooting this.
Could late-binding work? Or have I something missing from my code that makes the application more robust when operating on different versions of windows and excel?
I tried a late binding solution, however that didn't solve the problem, but I did manage to find a solution.
The excel worksheet the application copied had links to other excel worksheets - the links were outdated and not functioning correctly, which meant that every time the newly created worksheet was opened, a user had to select 'Enable Content' - not sure how I missed this!
I solved this problem by:
1) Fixing the links on the worksheet template being copied
2) Making the network drives, which held both the worksheet template and also the worksheets that the template had links to, trusted locations.
I have a large Excel file that uses PowerPivot to connect to several external data sources. The Excel file is stored in a SharePoint folder. I would like to be able to refresh the connections automatically overnight. To do this, I am using Windows Task Scheduler to trigger a VBScript each day at 2AM.
Previously, I had the script run a macro within the workbook to refresh all. This worked successfully until my organization recently updated to Microsoft Office 365 ProPlus. I am now struggling with the new read-only default setting for SharePoint. Following the update, whenever I open an Excel file from SharePoint, I see a yellow bar reading "Read-Only: We opened this workbook read-only from the server. Edit Workbook". When working with files manually, this has to be clicked before changes can be saved. I tried to research the programmatic workaround for this and found the recommendation to use the method .LockServerFile.
To streamline the trouble-shooting, I have tried to move the entire action into the VBScript script, rather than running a macro within the workbook. My code is below.
When I watch the process, the yellow "Read-Only" bar appears to pop up immediately before the save. I can run the process once with no apparent errors, but if I then manually open the file, I don't see the option to "Edit Workbook". If I manually change the file, save, and then run the script again, I get the error 800A03EC.
It seems that somehow the script is failing to correctly "release" the lock on the server file after it finishes.
Is there a way to fix this?
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("[[The Sharepoint Path]]")
objExcel.Application.DisplayAlerts = False
objExcel.Application.Visible = True
objExcel.ActiveWorkbook.LockServerFile
objExcel.ActiveWorkbook.EnableConnections
objExcel.ActiveWorkbook.Sheets(1).Range("P2").Value = Date
objExcel.ActiveWorkbook.RefreshAll
objExcel.ActiveWorkbook.Save
objExcel.ActiveWorkbook.Close false
objExcel.Application.Quit
set objworkbook = Nothing
set objExcel = Nothing
WScript.Quit
I have the following code in word VBA 2010
Dim oExcel As excel.Application
Dim oWB As workbook
Set oExcel = New excel.Application
Set oWB = oExcel.Workbooks.Open("C:\users\jane\desktop\excelSheet.xlsx")
oExcel.Visible = True
Set oWB = oExcel.Workbooks.Open()
it has throws a user defined type during the first line - basically, the code has no idea what an excel.Application is; but it knows what an Application is. How to make it know what an excel.Application is? Also, assuming it knows what an excel.Application is, would this code open excelSheet.xlsx at the given location?
In the VBA Editor go to Tools > References and check the Reference to Excel.
Here is a picture (check the line in blue):
You have to reference the Excel Vba Library to you Document. Below you see the Vba Editor Window from within a Word Document. You have to click on the menue point Extras and then on References (I am using a german version of Word so I am assumig that these points are named like that). Then you have to refrence the library you see in the picture (the version is not important, just pick whichever latest version is available to you).
When you did refrence it you should that lines like Dim oExcel As excel.Application change to Dim oExcel As Excel.Application, indicating that your VBA environment now knows what Excel. ... is. Please note that there are two ways to reference in VBA: early binding and late binding. When you reference as I described you use early binding, which is good for development but bad for everything else. To learn how to you late binding instead a first start would be this article.
Edit:
Oh someone answered faster. I will let this answer live though, so you can check the binding part.