Lotusscript Excel Error while opening the excel workbook - excel

Hi all I am getting error when i tried to import the data from the excel file. At the point when lotusscript opens the workbook i am getting error as `
" Microsoft Excel: Office has detected a problem with this file cannot be opened. Error in XlsWeb In Initialise 70"`
And in line number 70 I am trying to open the workbook.
Set xlsApp = CreateObject("Excel Application");
MessageBox varfilename
xlsApp.Workbooks.Open varfilename
In logs
E:\temp\09-09-2016042956AM.xls
I have some files which import correctly but the file which i received it is not able to open the FILE and giving me this error. Kindly let me know if there is any problem with the file. I guess in coding there is no error as we other files are working correctly

Don't use xlsApp.Workbooks.Open at all, but make Excel visible and give the user control
xlsApp.Visible = True
xlsApp.UserControl = True
then just 'End Sub' out of your routine.

Related

MS Access 'error 9 subscript out of range' saving an Excel workbook with VBA

I have an Access database split into a front and back-end, still using the mdb file format as user level security is required. Part of the db functionality is to create reports in Excel (via VBA). One of my routines uses a blank excel workbook as a template and copies it to paste the report data into. Users in the office have MS Office 365 on their desktop machines and each user has their own copy of the front-end database. The back end database sits on a server. These users have always been able to run this report and when I recently gave them an updated copy of the front-end they could still run this report. There was no change to the code that creates this report in the updated front-end database.
However there are some remote users on RDS. They were using a previous version of Office and this report worked. They were updated to Office 365 and the report worked. I gave them the updated front-end and they could not run the report. Below is the code:
Dim objExcel As Excel.Application
Dim objReportDataWrkbk As Excel.Workbook
'open Excel
On Error Resume Next
'Try first to use an existing instance.
Set objExcel = GetObject(, "Excel.Application")
If Err Then
'Excel wasnt running
Set objExcel = CreateObject("Excel.Application")
End If
On Error GoTo Err_ExportExternalReferralDataToExcel
'copy Excel template
objExcel.SheetsInNewWorkbook = 5
Set objReportDataWrkbk = objExcel.Workbooks.Add(strPathToExportTemplateFiles & strTemplateName)
objReportDataWrkbk.SaveAs strPathToTempExportFolder & strFileName
For RDS users the SaveAs line throws the error 'Error 9 subscript out of range'
I have stepped through the code and the part that starts Excel works - I can see Excel open.
The line that copies the workbook works - I can see the workbook open in Excel.
It hits the SaveAs line and I get my error.
I have done a Debug.Print of strPathToTempExportFolder & strFileName - and the path is valid and the file name is not something odd that may prompt an error.
I have tried modifying strPathToTempExportFolder to save in another location and I still get the error.
I am told by the office IT that the users have relevant network permissions to copy files and save files in the locations I have been trying.
Is there something blindingly obvious that I am missing here. Any help greatly appreciated.

Open Excel file in SharePoint through VBA

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

How to open a macro enabled Excel file on a SharePoint in edit mode from an Excel vba?

I have an macro enabled Excel file on a SharePoint that when a user opens it from the SharePoint the file opens programmatically another macro enabled Excel file on the same SharePoint. The file being opened by the vba macro needs to be edited, and must be editable by multiple users at the same time. However I can't get it to even open in edit mode. Using Office 365
I've tried << ActiveWorkbook.LockServerFile >> but always get an error message << Run-time error 1004: Method 'LockServer' of object'_Workbook' failed >>.
The code that I show below is in the Excel file that is opened manually by the user and that opens automatically the other Excel file. The other Excel file when opened works fine (if I remove the LockServerFile command), all it's macro's work fine, but it is open in read only and changes cannot be saved. Again this file should be editable by multiple users simultaneously.
' this code is in the "ThisWorkbook" tab
Sub workbook_open()
Set DB = Workbooks.Open(DBname, 3, False, , , , True)
ActiveWorkbook.LockServerFile ' this is where is crashes
'more code...
End Sub
' Note: DB is declared in a module
Public DB as Workbook
Public Const DBname As String = "https://ledvance365.sharepoint.com ... .xlsm"
Looks like << ActiveWorkbook.LockServerFile >> wasn't working because the SharePoint settings was not on "Open Documents in Client Applications by Default"
But once I got the SharePoint owner to change the SharePoint settings to "Open Documents in Client Applications by Default" the << ActiveWorkbook.LockServerFile >> command worked.
Maybe check out the following link to check if the file is already locked.
https://www.mrexcel.com/forum/excel-questions/906983-vba-support-checking-if-file-locked-sharepoint.html
Also in general it helps if you use your objects when you set them.
Dim DB as Workbook
Set DB = Workbooks.Open(filename:=DBname, editable:=True)
DB.LockServerFile
I had a similar issue. The code crashes at the same point you highlighted.
ActiveWorkbook.LockServerFile
Seems to fail when the document is already editable.
On Error Resume Next
ActiveWorkbook.LockServerFile
Fixes the issue I was experiencing since the code will continue on when the file is already editable and similarly makes a file editable if it wasn't previously.

Excel.Application.Visibile not working on Office 2016

I need help reguarding the following code written in Visual Basic 6.0.
Private Sub cmdExcel_Click()
Dim obj As Object
Set obj = CreateObject("Excel.Application")
On Error Resume Next
MkDir "c:\temp"
On Error GoTo 0
MousePointer = vbHourglass
On Error GoTo err
objGrid.m.ExportToXLS "c:\temp\test.xls"
obj.Workbooks.Open "c:\temp\test.xls"
obj.Visible = True
obj.Interactive = True
On Error GoTo 0
err:
MousePointer = vbNormal
End Sub
The enviroment: Windows 10, Office Excel 2016.
The problem: the workbook doesn't show up, but I can still find an Excel instance in Task Manager. If I shut down the instance I can find the Excel in c:\temp and the application starts working again.
The goal: show the Excel just created.
Do you have any solutions?
Thanks in advance.
Sara
I found the solution.
The problem wasn't in the code but in some Excel's settings.
First, I modified the code in order to get a more detailed error. Basically I switched the two instructions which allow Excel App to be visibile and the file to be opened:
obj.Visible = True
obj.Workbooks.Open "c:\temp\test.xls"
In this way, I was able to open Excel App and read the reason why the file could not be opened.
As you can see the file type is Excel 4 Worksheets which is blocked on opening.
I had to go Trust Center and disable it.
Just to be sure, I disabled also Excel 4 Workbook.
After performing the steps above, my app worked.

Excel VBA: Workbooks.Open(absolute_path) freezes Excel, except under one condition

Under this line of code, Workbooks.Open(previous_absolute_path) freezes Excel most of the time, giving no error message:
Set current_workbook = Workbooks(get_file_name(current_absolute_path))
The surounding code:
If IsWorkBookOpen((current_absolute_path)) = False Then
If previous_absolute_path <> "" And previous_absolute_path <> current_absolute_path Then
Workbooks(get_file_name(previous_absolute_path)).Close True
End If
Set current_workbook = Workbooks.Open(current_absolute_path)
previous_absolute_path = current_absolute_path
Else
Set current_workbook = Workbooks(get_file_name(current_absolute_path)) 'Causes Fail!
End If
current_absolute_path is a valid file path that is absolute. It seems every time the code runs there are windows at least being opened. However, in the newly opened workbook, no lines of code are ever executed in itsworkbook_open() from what I can tell from putting a message box as the first line of code ofworkbook_open() and the message box never appears.
The code does work, if and only if I have the workbook running this macro open, and before I run that macro, I manually open the workbook at current_absolute_path. I close that file and run the macro and it works without any problems.
current_absolute_path, is a confirmed valid file path. The line of code can open other workbooks within the same folder. Excel allows all macros and "trusts" files from the internet at this point. The folder of the workbook being opened is not protected.. and I do not have the skills yet to know where the problem is. What must be done?
EDIT: It's not manually opening the workbook that causes the Excel macro to run successfully the next time, specifically its manually closing it.

Resources