Excel - Application.GetSaveAsFilename Prompting on Read Only Files - excel

I've just upgraded to Excel 2010 from 2003. An internal add-in that is heavily used uses the Application.GetSaveAsFilename method to prompt for file names to be used for an export process (exporting information from the current Excel file into an xml configuration file).
In 2003, even if they selected a Read Only file, I didn't get any prompts (which is what I want) leaving it up to me to handle read-only issues (which I do...e.g. I check the file out of source control). However, after upgrading to 2010, I can't select a filename if that file exists and is readonly, forcing me to manually go checkout files first (which is a major downer in terms of proficiency when I'm exporting ~60 files per day).
Does anyone know of any settings/workarounds so that Excel 2010 doesn't prevent (or even prompt hopefully) selecting a filename of a previously existing/readonly file?
Thanks in advance.

Does it help if you use Application.GetOpenFilename instead?
Sub PromptForFilename()
ret = Application.GetOpenFilename
MsgBox ret
End Sub
This doesn't give me any errors for a read-only file.

Related

FileFormat:= 51 or 52 doesn't save file as an excel file

I am saving a file using the command
FilNam = "//drive/folder/Test"
File.SaveAs FileName:=FilNam, FileFormat:=51
File.SaveAs FileName:=FilNam, FileFormat:=52
Here is how it appears
But I am able to select this file and open with excel to see the data inside them. I would want this to appear as en excel file. How to fix this error.
As mentioned in the comments, it's better to include the extension when you name the file. In your case:
51 is for Open XML Workbook (*.xlsx)
52 is for Open XML Workbook With Macros Enabled (*.xlsm)
For all the possible file types, you can have a look at the XlFileFormat Enumeration page on the MSDN.
Additionally, as mentioned by Jeeped, if you are saving on a Windows location, the extension in the filename is not absolutely necessary since it should default automatically to the extensions mentioned above. Now, from the style of filename that you are using, I guess that you are saving the file to a remote Unix location which is probably why the extension is not added automatically. It should be different if you were saving on your desktop.

Excel vba open read only file error

I have a vba macro to open Excel files, including Read-only files.
I use the following code to do this:
Workbooks.Open((FileName:=MyFileName, UpdateLinks:=0, IgnoreReadOnlyRecommended:=True)
Up until June 2013 this never failed. As of now this no longer works. Now when the macro encounters a read-only file the file appears in a separate window and a Save As prompt also appears (never happened before).
If I click Cancel I get a Path not found error. If I click Save the file gets saved to its original location. This is completely new. There is no Save As command in this part of my code.
It appears to be something new associated with Microsoft’s File > Protect Workbook > Mark as final stuff. Anyone seeing this? I can’t find a way to prevent it. I simply want to be able to open the read only file without further prompts.
I haven't used VBA with excel much, but is it possible that the macro security settings within excel were reset so that it no longer trusts macros or VBA script attempting to use it.
Thanks for the input. I did find a work-around. In newer versions of Excel there is a new ReadOnly designation: Final, i.e. File > Protect workbook > Mark as Final. This is the same as ReadOnly, just by another name, and it does not show up as an option in WorkBooks.Open(FileName:= ...). If I set the Workbook.Final property = False, then I can open the file w/o the SaveAs prompt.
If wbName.Final = True Then
wbName.Final = False
End If

Importing .xls to Access .mdb: External Table is not in the expected format

I have a macro that imports a spreadsheet as follows: (this spreadsheet is an export from a web-based application, and during the initial export the chosen format is 97-2003)
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "d2s_safety_tbl", _
"\\company.com\dfsroot$\Share\office_public\D2S\D2S\D2S_Scorecard\Source Data\D2S\D2S Safety.xls", True
When importing to Access, I get:
Run-time Error '3274': External table is not in the expected format.
When I open this Excel file, I get a dialog
"The file you are trying to open is in a different format than specified by the file extension..."
So the file name is .xls, my computer tells me its the 97-2003 Format, but once I open the file and click save, it defaults to save it as a Web Page format with the option to save as .xls. What gives?
UPDATE: If I open the file, then Save As .xls format (seemingly redundant, but apparently not), it asks me if I want to overwrite the existing file, so I do. Once I go through this, the VBA import is successful. I can't have the clerk go through this process every week--any way to avoidd this? Possibly the initial export from the web-based application?
DoCmd.TransferSpreadsheet is refusing to import your .xls file because it is not really an .xls file, it is an HTML file that has been given an .xls file extension. Providing a "fake" file extension is a trick that I've seen other "developers" use, and it really is a Bad Idea (for the reasons we've seen here).
If the keepers of the upstream system balk at doing The Right Thing and fixing their code to produce a real .xls file then try renaming the ".xls" file to .htm and importing it using
DoCmd.TransferText acImportHTML, ...
I also got a 3274 error when importing a spreadsheet into Access. I have been using this macro for a while now.
The solution was to compact and repair the Access database.
I had the same problem along with another problem (office 2016 x64): Pasting from excel to access raised 'Data on the Clipboard is damaged,...' error. I found a workaround by clicking on the lower right button in paste section of home tab of access, opening the clipboard pane.
After opening Clipborad Pane as stated above, my DoCmd.TransferSpreadsheet surprisingly worked fine.
I don't know why but it may help those having the same problem and those trying to find a real solution.

End user difference between .xls and .xlsb?

I'm using the TransferSpreadsheet command to export Access queries to an Excel file in a folder. I realize I can specify a file name (with extension) for it to create, but I decided to experiment and left out a file name in the destination path. The result was an Excel file with the query name saved as a .xlsb file.
I'd never heard of this, but it opened fine and after research I found that it is a more compact, quicker to open/save/close than traditional .xls. Great! These exported Excel files will be opened by potentially 20-25 users, each of whom has one of Excel 03, 07, or 10. For flexibility's sake, I would prefer to export the query without defining a file name.
Is .xlsb compatible with all of these? If so, is there any reason to not use this format? Can the end user format, modify, or otherwise tinker with a .xlsb file as though it was .xls?
.xlsb was introduced in excel 2007 alongside .xlsx and .xlsm. All three formats use the OPC standard and are conceptually similar (whereas .xls, while also a binary format, is much different -- for example, it uses an OLE container format rather than zip)
.xlsb is not compatible with .xls, and AFAICT there are no open source tools that can write XLSB. The j tool (available on node npm at https://npmjs.org/package/j) appears to parse XLSB. If you expect others to use their own tools (not excel) then you are better off sticking with XLS. However, if Excel is part of the workflow, then XLSB is a compelling option

SWT OleClientSite: How to load XML file in Excel?

I have an Excel file in OfficeML format, MyData.xls. Since I upgraded to Office 2007 from Office 2003 I get a warning message saying that the file content does not match the file extension. It seems that OfficeML now must have the extension 'xml'.
In my application I use OleClientSite to display the file in an OleFrame object. If I change the file extension to 'xml' then Excel is not started. If I leave the extension as 'xsl' then I get the above warning message.
How can I force the file with the 'xml' extension to be opened in the OleFrame using Excel?
The easiest solution is to switch back to the 2003 format, which should not require any changes to your application. To do this, open your file with the extension set to *.xls. When prompted with the warning ("... do you want to open the file now?"), proceed to open (this is a warning to make sure you don't unintentionally open a macro-enabled file). Once in Excel and the file is open, simply save it as *.xls. This can be done by going to "Office Button / Save As / Excel 97-2003 Workbook".
Now, the harder solution will be upgrading your application to deal with the new OfficeML format. I don't know about the component you're using, but it will likely still work for some of the binary parts in the new standard (most notably VBA projects), but you're going to have to unpack and start reading XML files.
If you haven't already done this, create a new Excel workbook, save it as *.xlsx (the 2007 format) and in Explorer, change its extension to *.zip. Open it up and take a look around. For more in-depth on the files, I would start digesting this MSDN article.
Maybe I'm missing something, but shouldn't you just use .xslx as your extension? I'm assuming that by OfficeML, you're refering to Office Open XML.
The <?mso-application progid="Excel.Sheet"?> should be present in the XSL template used.
The below link explains clearly how to include the processing instruction. I had to do something similar and it worked for me.
http://www.shareyourwork.org/roller/ralphsjavablog/entry/generating_excel_sheets_with_xslt

Resources