I have a VFP9 application which generates Excel files using Automation, starting with :
**oExcel = CREATEOBJECT(“Excel.Application”)
oWorkbook = oExcel.Workbooks.Add()**
. . .
Excel 2013 is being used. The sheet is then populated, formatted and saved . This works fine on a Windows 7 32-bit machine. However on a Windows 7 64-bit machine, some instructions fail. In particular :
**oworkbook.SaveAs(<NewFilename>)**
fails with the message “Unable to get the SaveAs property of the workbook class”
As a work-around, I have created before creating the Excel object, and then called :
**oworkbook.Save ()**
This works. Have other users experienced this; are there any other limitations on the use of Excel from VFP when running on a 64-bit machine.
Thanks
Neither oWorkbook.SaveAs() nor oWorkbook.Save() have any problems on a 64 bit machine (I assume you meant windows (7/8/10) 64). Your problem should be something else.
I've experienced the identical problem but the issue turned out to be that the user had a different version of Excel than I did. It wasn't the 64 bit vs the 32 bit. I solved it by defining:
#define xlNormal 39
That set the target version of the workbook. Here is a page about the enumeration: https://msdn.microsoft.com/en-us/library/office/ff198017.aspx
I have also found that, in applications where I am saving up to like 50, that I have to open, set the save flag, do my work then say SaveAs.
Good luck with this :) Please consider closing this question. I think you get like two points for that.
Related
I have a very complex excel macro workbook. The VBA code seems to run pretty well on PC's at my location. As soon as I send it to a German colleague it fails to run in unexpected locations of the code.
The last problem I came across is a Runtime error 5 when the code try to modify the Caption of a UserForm (and some text boxes and cmd buttons as well).
Previously we faced with the same issue with SlicerCache(x).ClearManualFilter but somehow I healed itself...
My first thought was to break up the nest With and see which row causes the fail, but it's immediately the first row. I assume it'll do the same for all rows.
I have checked the windows and office settings:
I'm running Win10, English language settings and Hungarian formatting settings. -> Code running well.
My local colleagues run the same system with Hungarian language and formatting. -> Code running well.
The problematic colleague runs Win10 with German language and formatting settings. -> Code fails to run.
We both have the same Reference libraries in VBA editor, none missing. (I assume it's carried by the excel file itself.)
I have Microsoft 365 MSO (16.0.13801.21050) 32-bit, he running 16.013801.21004 32-bit. (I suppose the update scheduled by the IT department.) This portion of code months before my latest office update, so I don't think it's a cause.
The sub called by a CommandButton_Click event, and calls the user form zurueckExport. The form is deisgned so that can called for differnet purposes, so the captions have to be modified according to the needs.
I have ran out of ideas, don't see what and why cause it. Does anybody could give me some help to deal with this issue? I would be very glad.
Public Sub verExport()
With zurueckExport
.Caption = "Version Exportieren zum Creo"
.Label1.Caption = "Welche Version möchten Sie zum Creo exportieren?"
.CommandButtonExportieren.Visible = True
.CommandButtonZurueckladen.Visible = False
.CommandButtonKennlinie.Visible = False
.KennlinieFormat.Visible = False
.Show
End With
End Sub
The captions were too long, that generated the error message on the other computer.
Resolution:
I have added several different labels to the UserForm and modify their visibility instead of overwrite the caption.
Many thanks for #J0eBl4ck for the idea.
Good morning, afternoon, evening or whenever you are reading this.
That's the problem, I have a macro and two PC's
PC One (1): Which Run the macro perfectly.
PC Two (2) Which drops the error in the title.
The macro Connects SAPLogon, and PC Two breaks in this line:
Set Locx = CreateObject("SAP.LogonControl.1")
And here is the function:
Function SAPLogon() As Boolean
Set Lockx = CreateObject("SAP.LogonControl.1")
Set Conn = Lockx.NewConnection
Conn.Language = "S"
SAPLogon = Conn.logon(0, False)
Boths PC have the next exact vba references:
Visual Basic For Applications
Microsoft Excel 16.0 Object Library
OLE Automation
Microsoft Office 16.0 Object Library
Microsoft Forms 2.0 Object Library
SAP GUI Scripting API
But here is my big suspicion about why the macro doesn't run on PC Two:
PC One (1) Has Microsoft Office Personal Plus 2016 32-bit and PC Two Has Microsoft Office Personal Plus 2016 64-bit
The macro has been coded by another employee in 2002 (So I Think it's a 32-bit macro)
The question is:
Can 64 Bit Excel run 32 Bits Macros? How?
Thanks and Cheers
The issue here is that the SAP GUI is a 32bit application, and provides 32bit ActiveX controls for scripting in VBA. These will not work from 64bit Excel, however there is a solution. The comment above refers to another answer that explains more, but there are two solutions I'll summarise:
If you are able to install a new GUI then the latest version, 770 released February 2021 includes an optional install of 64bit NWRFC. This will install additional 64bit OCX controls that will work from 64bit Excel and VBA. (see https://stackoverflow.com/a/68906306/5087459).
If you need to use an older GUI then you will need to make a registry change using a surrogate as described in https://stackoverflow.com/a/65017544/5087459.
I have a question relating to the differences between the 32 bit and 64 bit versions of Excel and VBA.
I am working in Office 365, 64 bit. (I am using 64 bit because I ran into memory issues and as a test, to see if 64 bit works for our company). I am working on an Excel file which has a lot of VBA code used to gather product properties from SQL, calculate parameters from these properties, and output everything to another SQL database. In addition, the Excel file outputs PDF files.
The Excel file is stored as a template, so that users can open the template and save the new file to their respective workspace. At the moment, the users are using Office 365, 32 bit.
When I open the Excel template, Excel closes itself. It seems to crash before calculating the parameters on the new file. There is no error message; in the lower-right message box I can see that Excel doesn't get to the calculating stage.
However, when the other users open the file in 32-bit Excel, everything is fine.
I am not using pointers (no PtrSafe) and no LongLong variables.
I also have no compile errors.
I am currently rebuilding the Excel file by saving it as a file without macro's, and then copying the VBA modules - a different site mentioned the VBA code may be corrupt. I am halfway through adding macro's, and the error pops up again; the VBA code I have added last has been in use for about a year so I am tempted to exclude it as a culprit.
Where would you suggest I look to find the problem?
You're absolutely right of course. I have gone back to the last working version and began adding a text logfile, which would log the start and end of each procedure. I got lucky as the file crashed as I was doing this, and the logfile pointed me towards a procedure seemed to be working, until the right conditions were met for it to crash.
The procedure itself accesses global variables which were not initialised. I didn't catch errors that could occur properly. For some reason, this works fine in x86 Excel, doesn't trigger any problems in the compiler or during debugging but crashes in x64 Excel when enough memory is used.
Gekozen_Assen is the name of a global variable. It is a dictionary which contains information. I had tried to use .Exists as a method to test if the required item in the dictionary exists, but this doesn't work if the dictionary isn't initialized at all.
The errorous code:
GetFromGlobal = ""
If Global_Dictionary.Exists(Answer_Type) Then
GetFromGlobal = Global_Dictionary.Item(Answer_Type)
Else
GetFromGlobal = "Error!"
End If
Instead I should've been using "Is Nothing", the fixed code below:
If Global_Dictionary Is Nothing Then
GetFromGlobal = "Error: Dictionary not initialized"
Else
If Global_Dictionary.Exists(Answer_Type) Then
GetFromGlobal = Global_Dictionary.Item(Answer_Type)
Else
GetFromGlobal = "Error: Dictionary item not found"
End If
End If
I've looked through a lot of the other threads on this but none of those solutions has helped me. I'm trying to open Excel via Microsoft.Office.Interop.Excel to load data into a worksheet. I have tried this solution but that did not solve my issue. I have also seen others say that settings DispayAlerts to False helped them, however that did not resolve my issue. I even tried adding in a 5 second wait to give Excel time to fully open but still no luck. A small sample of my code that I'm using to open Excel is below. This is working without issues on two machines that I've installed my application on, but the third on (2012 R2 64-bit server running Excel 2010 32-bit) is causing me all kinds of headaches. Unfortunately, because I can't replicate this on my testing machine with Visual Studio installed, I can't debug the error. Any help would be greatly appreciated.
Dim _excel As New Excel.Application
Dim WBook As Excel.Workbook = Nothing
_excel.DisplayAlerts = False
WBook = _excel.Workbooks.Open(Path.Combine(FolderPath, FileName))
I was able to get this resolved. Creating an OleMessageFilter with this link and converting my BackgroundWorker to an STA Thread with help from this link seemed to do the trick. Had to pretty much rewrite my entire background process but at least it's working. Thanks for all the help!
OK, so i have a SmartGWT web application, where i have some reports running in list grids.
I export to excel using the Smartgwt built-in export as per the examples using the listgrid.exportclientdata();
Here's the issue:
-When running locally, all works fine and i can open the XLSX file and see all data.
-When running from the server, the columns containing data become hidden! If i manually do the "unhide" thing from within Excel, i can see the columns...
My local environment is Mac OSX, Mountain Lion(also tried earlier), running Sun's Java.
The prod server is Debian running OpenJDK.
Not sure if that would have something to do with it, and i am at a loss as to how i go about solving it... Running my webapp on Tomcat6 in both environments.
For others, searching the stackoverflow void for answers to riddles in the dark:
This was caused by certain fonts not being available in OpenJDK, without any errors being logged anywhere...
I switched to Sun's JDK on my Debian as well, and the Excel files now open and display properly.
This an also happen when facing this POI Bug that seems to be related to a Java Bug.
If it's the case changing the Font to something other than Calibri or using jre above 7u21 should fix the issue.
You can also mitigitate the issue and avoid the columns from being totally collapsed by using a code like this
sheet.autoSizeColumn(x);
if (sheet.getColumnWidth(x) == 0) {
// autosize failed use MIN_WIDTH
sheet.setColumnWidth(x, MIN_WIDTH);
}