The issue occurred because I was copying the xlsx file to another location and changing the copied file extension as xlsm.
Now, I first saved the <SourceFile>.xlsx as <SourceFile>.xlsm. Then, I copied <SourceFile>.xlsm to desired location keeping extension as ".xlsm".
This solved my issue.
Error while opening xlsm file
Hello folks,
I am building a dll file for autocad and trying to export the data of the symbols present in the current drawing to excel. I have a srcFile which is an xlsx file having template needed in this task. I am using a SaveFileDialog from which user can choose the location and type of excel files ( i.e. xlsx, xls, xlsm ) to export the data. After the user presses OK, I copy the srcFile to desired location with desired extension.
Here is the code:
Private Sub GetXLFile(ByRef xlFile As String)
Dim srcFile As String = String.Empty
SaveFileDialog1.DefaultExt = ".xls;.xlsx;.xlsm"
SaveFileDialog1.FileName = resManager.GetString("PartsList")
SaveFileDialog1.InitialDirectory = Environment.SpecialFolder.CommonDocuments
SaveFileDialog1.Title = resManager.GetString("SavePartsList")
SaveFileDialog1.AddExtension = True
SaveFileDialog1.Filter = "Excel Workbook (.xlsx)|*.xlsx|Excel 97-2003 Workbook (.xls)|*.xls|Excel Macro Enabled Workbook (*.xlsm)|*.xlsm"
Try
If SaveFileDialog1.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK Then
xlFile = SaveFileDialog1.FileName
Dim ext As String = System.IO.Path.GetExtension(xlFile)
If ext.Equals(".xls") Then
srcFile = "E:\PartsList Template xls.xls"
ElseIf ext.Equals(".xlsx") Then
srcFile = "E:\PartsList Template xlsx.xlsx"
ElseIf ext.Equals(".xlsm") Then
srcFile = "E:\PartsList Template xlsm.xlsm"
End If
My.Computer.FileSystem.CopyFile(srcFile, xlFile, True)
MsgBox(resManager.GetString("ErrorOccurredWhileExportingPartsListToExcel"), , Me.Text)
' Exit Sub'
End If
Catch ex As System.Exception
MsgBox(ex.Message & Environment.NewLine & resManager.GetString("ItMayBeOpenInAnotherApplication"), , Me.Text)
End Try
End Sub
Here is the image of savefiledialog
I successfully exported data to xlsx file and now I am trying the same with xlsm file. There is no exception throughout the execution of code but when I am trying to open the xlsm file in excel, it is showing this error.
What I have tried :
- I went to Options\Trust Center\ Trust center Settings\ Macro Settings in EXCEL Application and chose the option "Enable All Macros" same as below. But the problem remained same.
- I am using Visual studio. I went to Properties of my project\compile tab and chose x86 as Target CPU. But after this, I couldn't load my dll file in autocad through NETLOAD command.
Can anyone tell me what I can do to open xlsm file in excel?
Thanks in advance.
Note: I have MS Office 365 and using .Net framework 4.8 to build project.
Developer technologies | VB
Developer technologies | C#
-
Rashmi Gupta 96 Reputation points
2021-05-12T08:14:55.167+00:00
1 additional answer
Sort by: Most helpful
-
Timon Yang-MSFT 9,606 Reputation points
2021-05-12T05:41:52.803+00:00 I have a guess. Even though you named the file xx.xlsm, in fact, it is still an xlsx file, and the format will not change with subsequent suffix changes.
If the file is generated by code, please show some code. The API should provide a method for generating xlsm files. If it is generated by their software, then I suggest you go to the forum they provide to ask this question.
Or you can try to modify its suffix to xlsx, and then save it as an xlsm file in Excel.
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.