2017-05-02 88 views
-2

尊敬的專家明確名稱檢測,請找我的地方我對着編譯錯誤代碼如下:檢測明確名稱錯誤RangetoHTML = Replace函數。請幫我出去一樣。編譯錯誤:郵件功能

 Function RangetoHTML(rng As Range) 

       Dim fso As Object 
       Dim ts As Object 
       Dim TempFile As String 
       Dim TempWB As Workbook 


       TempFile = Format(Now, "dd-mm-yy h-mm-ss") & ".htm" 
       Set x = ActiveWorkbook 
       Set TempWB = x 

       Set rng = Nothing 
       Set rng = ActiveSheet.UsedRange 

       With TempWB.PublishObjects.Add(_ 
        SourceType:=xlSourceRange, _ 
        Filename:=TempFile, _ 
        Sheet:=TempWB.Sheets(2).Name, _ 
        Source:=TempWB.Sheets(2).UsedRange.Address, _ 
        HtmlType:=xlHtmlStatic) 
        .Publish (True) 
       End With 


       Set fso = CreateObject("Scripting.FileSystemObject") 
       Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2) 
       RangetoHTML = ts.readall 
       ts.Close 
    M= RangetoHTML  
RangetoHTML = Replace(M, "align=center x:publishsource=", "align=left x:publishsource=") 

    ''In Above code RangetoHTML for Replace I am facing the error. 


    Set ts = Nothing 
       Set fso = Nothing 
       Set TempWB = Nothing 
      End Function 
+2

這是怎麼涉及到'C++'?如果你的第一件事是'Set rng = Nothing',那麼函數的作用是什麼? –

+0

創建一個本地字符串變量來代替RangeToHTML。在離開函數之前將該變量分配給RangeToHTML。 –

+0

@RichHolton我有** ** **變量來代替** RangetoHTML ** **我已經在我的代碼中更新過了。現在我面臨着**錯誤的參數數量或無效的屬性分配**錯誤。 – sagar

回答

1

正如裏克已經建議...你可以試試這個

Function RangetoHTML(rng As Range) 

      Dim fso As Object 
      Dim ts As Object 
      Dim TempFile As String 
      Dim TempWB As Workbook 


      TempFile = Format(Now, "dd-mm-yy h-mm-ss") & ".htm" 
      Set x = ActiveWorkbook 
      Set TempWB = x 

      Set rng = Nothing 
      Set rng = ActiveSheet.UsedRange 

      With TempWB.PublishObjects.Add(_ 
       SourceType:=xlSourceRange, _ 
       Filename:=TempFile, _ 
       Sheet:=TempWB.Sheets(2).Name, _ 
       Source:=TempWB.Sheets(2).UsedRange.Address, _ 
       HtmlType:=xlHtmlStatic) 
       .Publish (True) 
      End With 

     Set fso = CreateObject("Scripting.FileSystemObject") 
     Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2) 
        M = ts.readall 
        ts.Close 
        M = Replace(M, "align=center x:publishsource=", "align=left x:publishsource=") 
     ''In Above code RangetoHTML for Replace I am facing the error. 
        RangetoHTML = M 

     Set ts = Nothing 
     Set fso = Nothing 
     Set TempWB = Nothing 
     End Function 
+0

我仍然面臨同樣的錯誤,你能幫助我如何以其他任何方式設置對齊方式(即=左)。 – sagar

+0

你從哪裏得到錯誤? M在電話給Replace之前有什麼價值?也許你應該Dim M作爲字符串? –