We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose.Words for .NET does not save macro enabled document to DOCX | VBA project

hi when i upload fie i get this error message

“This document contains macros (VBA project) and you are attempting to save it in a Macro-Free format. Such document will be invalid if created”

i add you sample of code

Partial Class insertLogo
    Inherits System.Web.UI.Page
    'Public imagePath As String = Request("logo")
     Public cvHTMLBody as String

    '--- make htmlFile

    'Dim cvBody = Request("HtmlCodeText")
    'cvBody = "/3_uploadFiles/"
   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
	      '---=== 0. Get Variables   ===--
        Dim errText as string = ""  
        cvHTMLBody = Request("HtmlCodeText")
        ' cvHTMLBody = "dadad"
        Dim fileName As String = Request("fileName")       : if fileName = "" AND cvHTMLBody = "" then errText = "Error: fileName is empty"
        Dim logoUrl As String = Request("logoUrl")
        Dim logoBinFile As String = Request("logoBinFile") : if logoUrl = "" AND logoBinFile = "" then errText = "Error: logoUrl and logoBinFile is empty"
        if errText <> "" then 
        end if    
	      '---=== 1. Set license   ===--
        Dim WordPath As String = HttpContext.Current.Server.MapPath("\Bin\Aspose.Words.lic")
        Dim PDFPath As String = HttpContext.Current.Server.MapPath("\Bin\Aspose.pdf.lic")

        Dim license As New Aspose.Words.License()
        Dim license1 As New Aspose.pdf.License()
        Dim fileFolder as string  
        if Request.Url.Host = "cvparsing.net-royal.off" Then
          fileFolder = "C:\inetpub\wwwroot\off.net-royal.cvparsing\3_uploadFiles\"
          fileFolder = "C:\inetpub\wwwroot\cvparsing.net-royal.com\3_uploadFiles\"
        end if  
        'dim fileName as string   : fileName = "test.docx"
        ' ---==== 1.0 if this binary filel
        if fileName <> "" then 
          '---=== 1.1 open document from disk ===--
           Dim docWord As New Aspose.Words.Document(fileFolder + fileName)
          Dim builder As New DocumentBuilder(docWord)
          '---=== 2. Change document to edit mode ===--
          builder.CurrentParagraph.ParagraphFormat.Alignment = 2
          ' ---=== 3. Open Logo File ===--
          Dim imageFileName  As System.Drawing.Image
          if logoUrl  <> "" then 
              '---=== 3.1 Open From Url ===--
              Dim wc As New WebClient()
              Dim bytes As Byte() = wc.DownloadData(logoUrl)
              Dim ms As New MemoryStream(bytes)
              imageFileName = System.Drawing.Image.FromStream(ms)
              '---=== 3.2 Open From Local disk ===--
              imageFileName = System.Drawing.Image.FromFile(fileFolder & "logo.jpg")
          end if
          Dim logoStream As New MemoryStream()  
          docWord.Save(logoStream, SaveFormat.Docx)
          '---=== response binary for debuging ===--
          Response.AddHeader("Content-Description", "File Transfer")
          Response.ContentType = "application/octet-stream" 
          'Response.AddHeader("content-disposition", "attachment; filename=" + _documentNameDated + ".docx")
          Response.AddHeader("content-disposition", "attachment; filename=test.docx")
          Response.AddHeader("Content-Transfer-Encoding", "binary")
          response.end end if

example.zip (38.5 KB)


Your document contains the macros. So, to avoid this exception, please save document to DOC or DOCM save format. If you want to save the document to DOCX file format, you can remove the macros from the document using Document.RemoveMacros method.