VBA的例子:
Function CreateNewWorkbook(Optional strBookName As String = "", _
      Optional intNumSheets As Integer = 3) As Workbook
   ' This procedure creates a new workbook file and saves it by using the path
   ' and name specified in the strBookName argument. You use the intNumsheets
   ' argument to specify the number of worksheets in the workbook;
   ' the default is 3.
   Dim intOrigNumSheets      As Integer
   Dim wkbNew                As Excel.Workbook
   
   On Error GoTo CreateNew_Err
   
   intOrigNumSheets = Application.SheetsInNewWorkbook
   If intOrigNumSheets <> intNumSheets Then
      Application.SheetsInNewWorkbook = intNumSheets
   End If
   Set wkbNew = Workbooks.Add
   If Len(strBookName) = 0 Then strBookName = Application.GetSaveAsFilename
   wkbNew.SaveAs strBookName
   Set CreateNewWorkbook = wkbNew
   Application.SheetsInNewWorkbook = intOrigNumSheets
   
CreateNew_End:
   Exit Function
CreateNew_Err:
   Set CreateNewWorkbook = Nothing
   wkbNew.Close False
   Set wkbNew = Nothing
   Resume CreateNew_End
End Function

解决方案 »

  1.   

    dim appwd As Word.Application
       dim mydoc As Word.Document
       dim fpath as string 
       fpath = "...."
       Set appwd = CreateObject("word.application") '创建 word  application 对象  
      With appwd
             .Visible = False
              Set mydoc = .Documents.Open(fpath) '调用word文档
              mydoc.Activate
          .....
               mydoc.SaveAs Trim(fpath)
          .......
       end with
       
      

  2.   

    VBProject和VBE的SaveAs,哪位大侠有啊?急用啊!谢了!
      

  3.   

    VBE的例子您可以看看这个
    http://msdn.microsoft.com/code/default.asp?url=/code/sample.asp?url=/msdn-files/026/000/006/msdncompositedoc.xml
      

  4.   

    '======================================================================= 
    'Synopsis:          Export (save) a VBA Project from the IDE to the Exporter 

    'Function input:    VBProj              - [IN] The VB Project to export 
    '                   ApplicationGUID     - [IN] The MT Project application object GUID 
    '                   ApplicationRegPath  - [IN] The MT Project registry path 

    'Function output:   - 

    'Possible errors: 
    '   icNotStandalone 
    '   icAmbiguousDesigner 
    '   icUnknownComponent 
    '   icCompileFail 
    '   icIOError 
    '   icRegisterServerFail '======================================================================= Public Function ExportVBAProject(ByRef VBProj As VBIDE.VBProject, _ 
                                     ByVal ApplicationGUID As String, _ 
                                     ByVal ApplicationRegPath As String) As Boolean 
                                    
        Dim VBComp As VBIDE.VBComponent 
        Dim TheStream As Stream 
        Dim NumDesigners As Integer 
        Dim FileSystem As New Scripting.FileSystemObject 
        Dim OriginalInProcServ As String 
        Dim TmpFileRoot As String 
        Dim ProjRef As Variant 
         
        TmpFileRoot = TempFileName(FileSystem.GetTempName) 
        TmpFileRoot = Left(TmpFileRoot, (Len(TmpFileRoot) - 4)) 
         
        '   Only works for standalone projects 
        ' 
        If (VBProj.Type <> vbext_pt_StandAlone) Then 
            ExportVBAProject = False 
            Err.Raise icNotStandalone, scErrSource, scErrNotStandalone 
            Exit Function 
        End If 
         
        '   Setup temp directory and remove any existing files from export folder 
        ' 
        CleanDir m_sTmpDir 
         
        '   Get the prog ID from the Project and designer names 
        ' 
        NumDesigners = 0 
        For Each VBComp In VBProj.VBComponents 
            If (VBComp.Type = vbext_ct_ActiveXDesigner) Then 
                msVBProjProgID = VBProj.Name & "." & VBComp.Name 
                NumDesigners = NumDesigners + 1 
            End If 
        Next 
        If (NumDesigners <> 1) Then 
            Err.Raise icAmbiguousDesigner, scErrSource, scErrAmbiguousDesigner 
        End If 
         
        '   Get the inproc server for the ProgID before registering anything. This mean it can be 
        '   put back afterwards 
        ' 
        GetMTProjectInfo ProgId:=msVBProjProgID, _ 
                         RegPath:=ApplicationRegPath, _ 
                         InProcServ:=OriginalInProcServ 
         
        '   Create the DLL 
        ' 
        VBProj.BuildFileName = TmpFileRoot & ".DLL" 
         
        On Error GoTo MakeCompiledFileFailed 
        VBProj.MakeCompiledFile 
        On Error GoTo 0 
         
        '   Get the new FriendlyName before unregistering 
        ' 
        GetMTProjectInfo ProgId:=msVBProjProgID, _ 
                         RegPath:=ApplicationRegPath, _ 
                         FriendlyName:=msFriendlyName 
                          
        '   Unregister the DLL, these should not be registered on the local machine 
        ' 
        UnregisterDLL TmpFileRoot & ".DLL" 
         
        '   Reregister original DLL for this ProgID if there was one 
        ' 
        If (OriginalInProcServ <> "") Then 
            RegisterDLL OriginalInProcServ 
        End If     '   Cache some of these as read only properties 
        ' 
        msVBProjApplicationRegPath = ApplicationRegPath 
                 
        '   Write VBA Project details to separate stream 
        ' 
        On Error GoTo WriteError 
        Set TheStream = moTheStorage.CreateStream("THE_PROPERTIES", axAccessWrite) 
        TheStream.Put icVBA_PROPERTIES 
        TheStream.Put ApplicationGUID 
        TheStream.Put msVBProjApplicationRegPath 
        TheStream.Put msFriendlyName 
        TheStream.Put msVBProjProgID 
    #If APC62 Then 
    #Else 
        TheStream.Put VBProj.BuildFileName 
        TheStream.Put VBProj.Description 
        TheStream.Put VBProj.HelpContextID 
        TheStream.Put VBProj.HelpFile 
        TheStream.Put VBProj.Name 
    #End If 
        Set TheStream = Nothing 
         
    #If APC62 Then 
        Set TheStream = moTheStorage.CreateStream("THE_PROJECTFILE", axAccessWrite) 
        TheStream.Put icVBA_PROJECTFILE 
        VBProj.SaveAs TmpFileRoot & ".VBA" 
        StreamFromFile TmpFileRoot & ".VBA", TheStream 
        Set TheStream = Nothing 
    #Else 
        '   Write VBA Project reference typelib details to separate stream 
        ' 
        Set TheStream = moTheStorage.CreateStream("THE_REFERENCES", axAccessWrite) 
        TheStream.Put icVBA_REFERENCES 
        TheStream.Put VBProj.References.Count 
        For Each ProjRef In VBProj.References 
            TheStream.Put ProjRef.Guid 
            TheStream.Put ProjRef.Major 
            TheStream.Put ProjRef.Minor 
        Next 
        Set TheStream = Nothing 
             
        '   Loop over the VBA Project contents exporting each bit and saving it to a stream 
        ' 
        For Each VBComp In VBProj.VBComponents 
            Dim TmpFile As String 
            TmpFile = FileSystem.GetTempName 
             
            '   Export VBA code 
            ' 
            VBComp.Export TmpFileRoot & ".TMP" 
             
            '   VBA code type specific stuff, some exports create two files 
            ' 
            Set TheStream = moTheStorage.CreateStream(VBComp.Name, axAccessWrite) 
            TheStream.Put VBComp.Type 
            Select Case VBComp.Type 
            Case icVBA_DESIGNER 
                StreamFromFile TmpFileRoot & ".TMP", TheStream 
                StreamFromFile TmpFileRoot & ".DSX", TheStream 
                TheStream.Put VBComp.Name 
            Case icVBA_MSFORM 
                StreamFromFile TmpFileRoot & ".TMP", TheStream 
                StreamFromFile TmpFileRoot & ".FRX", TheStream 
            Case icVBA_MODULE 
                StreamFromFile TmpFileRoot & ".TMP", TheStream 
            Case icVBA_CLASS 
                StreamFromFile TmpFileRoot & ".TMP", TheStream 
            Case Else 
                ' This should never happen 
                Set TheStream = Nothing 
                ExportVBAProject = False 
                Err.Raise icUnknownComponent, scErrSource, scErrUnknownComponent 
            End Select 
            Set TheStream = Nothing 
        Next 
    #End If     '   Write the MT Project DLL to the stream too 
        ' 
        Set TheStream = moTheStorage.CreateStream("THE_DLL", axAccessWrite) 
        TheStream.Put icVBA_DLL 
        StreamFromFile TmpFileRoot & ".DLL", TheStream 
        Set TheStream = Nothing 
         
        moTheStorage.Commit True 
        ExportVBAProject = True 
         
        Exit Function 
         
    MakeCompiledFileFailed: 
        Set TheStream = Nothing 
        ExportVBAProject = False 
         
        '   Re-describe automation errors, pass through other, more descriptive errors. 
        '   Note, the HRESULT is E_FAIL in both cases. 
        ' 
        Err.Raise icCompileFail, scErrSource, scErrCompileFail 
        Exit Function 
         
    WriteError: 
        Set TheStream = Nothing 
        ExportVBAProject = False 
        Err.Raise icIOError, scErrSource, scErrIOError 
         
    End Function
      

  5.   

    这个页面
    http://msdn.microsoft.com/code/default.asp?url=/msdn-files/026/000/006/Servers/Visual%20Basic/Export/export_cls.asp