I am using a VBScript to convert a xls file to csv. The process seems to be working how I need it except after the file gets converted my script won't close Excel. Both files remain open in excel preventing them from being updated or opened by other apps.
Here is the script I am using:
Set ExcelObj = CreateObject("Excel.Application")
ExcelObj.DisplayAlerts = True
ExcelObj.Visible = false
ExcelObj.Workbooks.Open "P:\Pro2010\folder\Ovations\ovations.xls"
ExcelObj.Workbooks(1).SaveAs "P:\Pro2010\folder\Ovations\edited\company-JULY-TEST.csv", 6
OverwriteExisting
oExcel.Quit
When I open the file in Excel after the script has run it says "The file is in use by 'Another user'. Open a read Only?'
change
oExcel.Quit
to this
ExcelObj.Quit
Related
I have the following simple VBScript for updating an Excel workbook.
Dim objExcel
Set objExcel = CreateObject("Excel.application")
objExcel.DisplayAlerts = False
objExcel.Visible = False
objExcel.Workbooks.Open "path\myworkbook.xlsx"
objExcel.ActiveWorkbook.RefreshAll
objExcel.ActiveWorkbook.Save
objExcel.Quit
Set objExcel = Nothing
When I use path to local excel file like C:\Users\sbrbot\Documents\myworkbook.xlsx the script works and updates my excel workbook fine. But when I use the remote path like \\sharepoint\library\myworkbook.xlsx then script executes without errors (so path is correct) but the workbook is not really updated! (SharePoint version 2013). Even if I map SharePoint's remote server path \\sharepoint\library to logical M:\ drive, and my path is M:\myworkbook.xlsx the same is hapening, it does not update workbook. Seems like SharePoint refuses to update file. Path is correct, that's not the problem.
I have to mention one strange bahaviour with SharePoint. When I manually open Excel file from SharePoint remote directory, make some changes in it, and save the file - in Excel's titlebar it is reported as Saved. Immediately after this when I go to close this Excel file, Excel asks me to save it again although I did not change anything inside the file.
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.
Below a VBS code converts .xls into .csv.
Set oBook = oExcel.Workbooks.Open(sfile)
oBook.SaveAs fulldest, 6
oBook.Close False
If works fine for most files but one of them has the usual Excel found unreadable content in filename.xls'. do you want to recover the contents of this workbook ? If you trust the source of this workbook, click Yes..
When the .Workbooks.Open method executes for this file, I get Unable to get the Open property of the Workbooks.
I tried oExcel.Workbooks.Open(sfile, xlRepairFile) without success.
I want to open and save an excel file in sharepoint, which has no excel installed. I tried to write an vbscript but I only can find which called excel application. Please help to advise. Thank you!
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("D:\Roambi\Test excel\Test.xlsx")
objExcel.ActiveWorkbook.Save
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
WScript.Quit
I am not sure about the reason of the issue, but if you need open and modify some content - maybe Open XML SDK could help. However if you need to open to run some script inside that file - you'll need to have installed Excel application
I have a large CSV file and I want to programmatically open it in excel with a particular line highlighted (I know the line number). What is the easiest way to this?
I think my options are:
Auto convert the csv file to an xlsx file. How can I do this from a script?
Give Excel some arguments when it opens up. No idea what command line arguments Microsoft products take.
Somehow interact with Excel after it opens up the CSV file and tell it to highlight a particular. Again not sure how.
I prefer Java/Python/Shell or anything that would work across Mac/Windows assuming the system has Excel installed. So, my best bet is probably #1 which brings me back to the question how can I convert a CSV file to a xlsx file.
You could run a basic vbs which avoids the need to have Excel already open, and conversion isn't necessary.
Paste the code below into a text editor NotePad
Change the path to your CSV file to suit (ie "c:\temp\test2.csv")
Save the file as something like MyCSV.vbs say to your Desktop
Click on the final vbs to open the CSV file to Row X (8 in the sample below)
Dim objExcel
Dim WB
Set objExcel = CreateObject("excel.application")
Set WB = objExcel.Workbooks.Open("c:\temp\test2.csv")
With objExcel
.Goto WB.Sheets(1).Rows(8)
.Visible = True
End With
this works simple save it in an empty workbook.
Private Sub Workbook_Open()
Workbooks.Open ("test.csv")
Range("8:8").Select
End Sub
also if you save that in your normal.dot (the default template document when opening excel) it will run on any document it opens. so what you could do is:
save this to your normal.dot
Private Sub Workbook_Open()
Range("8:8").Select
End Sub
then change the default application for opening .csv files to excel. then whenever you double-click on .csv file it will be opened with excel and excel will run the Workbook_Open() sub and viola!