Excel vba

Disponível somente no TrabalhosFeitos
  • Páginas : 3 (574 palavras )
  • Download(s) : 0
  • Publicado : 25 de novembro de 2011
Ler documento completo
Amostra do texto
Control Excel from Word using VBA in Microsoft Excel
VBA macro tip contributed by Erlandsen Data Consulting offering Microsoft Excel Application development, template customization, support andtraining solutions
CATEGORY - Applications - Word, Outlook in VBA VERSION - All Microsoft Excel Versions
The two example macros below demonstrates how you can send information to Excel from Word(e.g. creating a new workbook) and how you can retrieve information from Excel (e.g. reading information from a workbook).
Note! Read and edit the example code before you try to execute it in your ownproject!
Sub CreateNewExcelWB()
' to test this code, paste it into a Word module
' add a reference to the Excel-library
' create anew folder named C:\Foldername or edit the filnames in the code
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim i As IntegerSet xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWB = xlApp.Workbooks.Add ' create a new workbook
' or'Set xlWB = xlApp.Workbooks.Open("C:\Foldername\Filename.xls")
' open an existing workbook
' example excel operationsWith xlWB.Worksheets(1)
For i = 1 To 100
.Cells(i, 1).Formula = "Here is a example test line #" & i
Next iIf Dir("C:\Foldername\MyNewExcelWB.xls") <> "" Then
Kill "C:\Foldername\MyNewExcelWB.xls"
End If.SaveAs ("C:\Foldername\MyNewExcelWB.xls")
End With
xlWB.Close False ' close the workbook without saving
xlApp.Quit ' close the Excel...
tracking img