VBA/Excel/Access/Word/Access/Access Import Export

Материал из VB Эксперт
Перейти к: навигация, поиск

Export table as html page

   <source lang="vb">

Public Sub ExportTable()

  DoCmd.OutputTo acOutputTable, "tblCustomer", acFormatHTML, _
                 "C:\BegVBA\Customer.html"

End Sub

</source>
   
  


Export table as htx file

   <source lang="vb">

Public Sub ExportTable()

  DoCmd.OutputTo acOutputTable, "tblCustomer", acFormatIIS, _
                 "C:\BegVBA\Customer.htx"

End Sub

</source>
   
  


Export table as rtf file

   <source lang="vb">

Public Sub ExportTable()

  DoCmd.OutputTo acOutputTable, "tblCustomer", acFormatRTF, _
                 "C:\BegVBA\Customer.rtf"

End Sub

</source>
   
  


Export table as txt file

   <source lang="vb">

Public Sub ExportTable()

  DoCmd.OutputTo acOutputTable, "tblCustomer", acFormatTXT, _
                 "C:\BegVBA\Customer.txt"

End Sub

</source>
   
  


Export table as xls file

   <source lang="vb">

Public Sub ExportTable()

  DoCmd.OutputTo acOutputTable, "tblCustomer", acFormatXLS, _
                 "C:\BegVBA\Customer.xls"

End Sub

</source>
   
  


Export table to asp page

   <source lang="vb">

Public Sub ExportTable()

  DoCmd.OutputTo acOutputTable, "Employees", acFormatASP, _
                 "C:\Customer.asp"

End Sub

</source>
   
  


Export to a Comma Separated File

   <source lang="vb">

Sub export()

    DoCmd.TransferText acExportDelim, "CompanyDelimited", "tblCompany", _
          "C:\Delimited.txt", True
    MsgBox "Company details exported"

End Sub

</source>
   
  


Export to a Fixed Width File

   <source lang="vb">

Sub text()

       DoCmd.TransferText acExportFixed, "CompanyFixed", "tblCompany", _
             "C:\Fixed.txt", True
       MsgBox "Company details exported"

End Sub

</source>
   
  


Importing from a Comma Separated File

   <source lang="vb">

Sub main()

    DoCmd.TransferText acImportDelim, "CompanyDelimited", "tblCompanyDelimited", _
          "C:\Delimited.txt", True
    MsgBox "Company details imported"

End Sub

</source>
   
  


Importing from a Fixed Width File

   <source lang="vb">

Sub import()

    DoCmd.TransferText acImportFixed, "CompanyFixed", "tblCompanyFixed", _
          "C:\Fixed.txt", True
    MsgBox "Company details imported"

End Sub

</source>
   
  


Transfer database through ODBC

   <source lang="vb">

Sub TestLinkTransferDatabase()

   DoCmd.TransferDatabase acLink, "ODBC Database", _
       "ODBC;DSN=DataSourceName;UID=username;PWD=pwd;LANGUAGE=us_english;" _
       & "DATABASE=yourDatabase", acTable, "Sales", "dboSales"

End Sub

</source>