Hello,
I need help with two areas in the following marco. The macro is extracting data from EXCEL into WORD. I'm trying insert data from the sheet into my HeaderFooter and create a list from the STEPS cell. More details are in the marco:
Sub ExceltoWord()
' ExceltoWord Macro
' Creates ExceltoWord documents using Automation
Dim WordApp As Object
' Start Word and create an object (late binding)
Set WordApp = CreateObject("Word.Application")
' Information from worksheet
Set Data = Sheets("MySheet001").Range("A1")
' Cycle through all records in MySheet001
Records = Application.CountA(Sheets("MySheet001").Range("A:A"))
For i = 1 To Records
' Update status bar progress message
Application.StatusBar = "Processing ExceltoWord number " & i
' Assign current data to variables
Number = Data.Cells(i, 1).Value
Description = Data.Cells(i, 2).Value
Users = Data.Cells(i, 3).Value
Steps = Data.Cells(i, 4).Value
' Determine the file name
SaveAsName = ThisWorkbook.Path & "\" & Number & " - " & Users & ".doc"
' Send commands to Word
With WordApp
.Documents.Add
With .Selection
' Wordmacro_Starts_here
'-------------------------------------------------------------------
'Please Help ---> with HeaderFooter code below
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.Font.Name = "Arial"
Selection.Font.Size = 8
Selection.Font.Bold = wdToggle
Selection.TypeText Text:="Number ID: Number"
Selection.Font.Bold = wdToggle
Selection.TypeParagraph
If Selection.Font.Underline = wdUnderlineNone Then
Selection.Font.Underline = wdUnderlineSingle
Else
Selection.Font.Underline = wdUnderlineNone
End If
Selection.TypeText Text:="Audience: Users" & vbTab & vbTab & _
"Version: 1.0"
If Selection.HeaderFooter.IsHeader = True Then
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If
Selection.Font.Name = "Arial"
Selection.Font.Size = 8
Selection.TypeText Text:="Confidential" & vbTab & _
"(c) My Company Inc., 2005" & vbTab
NormalTemplate.AutoTextEntries("Page X of Y").Insert Where:=Selection. _
Range, RichText:=True
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
'Please Help ---> HeaderFooter code end here
'-------------------------------------------------------------------
.Font.Name = "Arial"
.Font.Size = 18
.Font.Bold = True
.TypeText Text:="Audience_Operators:" & " " & Users
.Font.Size = 12
.TypeParagraph
.TypeParagraph
.TypeParagraph
.TypeText Text:="1. Description"
.Font.Size = 10
.Font.Bold = False
.TypeParagraph
.TypeParagraph
.TypeText Text:="" & Description
.TypeParagraph
.TypeParagraph
.TypeParagraph
.Font.Size = 12
.Font.Bold = True
.TypeText Text:="2. Users"
.Font.Size = 10
.Font.Bold = False
.TypeParagraph
.TypeParagraph
.TypeText Text:="2.1" & vbTab & Users
.TypeParagraph
.TypeParagraph
.Font.Size = 12
.Font.Bold = True
.TypeText Text:="4. Flow of Events"
.Font.Size = 10
.Font.Bold = False
.TypeParagraph
.TypeParagraph
.TypeText Text:="4.1 Basic Flow"
.TypeParagraph
.TypeParagraph
.TypeText Text:="" & Steps
'------------------------------------------------------------------
Please Help
I need some code placed here (preferably) that will take data thats coming from Excel and put it into Word on a newline when/if the numbers 1-20 are listed. The data is coming from a column named "Steps" in my Excel docment.
Right now the raw data wrapps in my Word report...
1. The user moves...command. 2. The user enters.... 3. The system retrieves customer account. 4. The System displays warnings messages. 5. The user selects to delete warning(s). 6. The system updates records.
What I need is code that will goto a newline when/if the numbers 1-20 are listed...
1. The user moves...command.
2. The user enters....
3. The system retrieves customer account.
4. The System displays warnings messages.
5. The user selects to delete warning(s).
6. The system updates records.
'------------------------------------------------------------------
.TypeParagraph
.TypeParagraph
End With
'Wordmarco_END_here
.ActiveDocument.SaveAs Filename:=SaveAsName
End With
Next i
' Kill the object
WordApp.Quit
Set WordApp = Nothing
' Reset status bar
Application.StatusBar = ""
MsgBox Records & " ExceltoWord documents were created and save in " & ThisWorkbook.Path
End Sub
I need help with two areas in the following marco. The macro is extracting data from EXCEL into WORD. I'm trying insert data from the sheet into my HeaderFooter and create a list from the STEPS cell. More details are in the marco:
Sub ExceltoWord()
' ExceltoWord Macro
' Creates ExceltoWord documents using Automation
Dim WordApp As Object
' Start Word and create an object (late binding)
Set WordApp = CreateObject("Word.Application")
' Information from worksheet
Set Data = Sheets("MySheet001").Range("A1")
' Cycle through all records in MySheet001
Records = Application.CountA(Sheets("MySheet001").Range("A:A"))
For i = 1 To Records
' Update status bar progress message
Application.StatusBar = "Processing ExceltoWord number " & i
' Assign current data to variables
Number = Data.Cells(i, 1).Value
Description = Data.Cells(i, 2).Value
Users = Data.Cells(i, 3).Value
Steps = Data.Cells(i, 4).Value
' Determine the file name
SaveAsName = ThisWorkbook.Path & "\" & Number & " - " & Users & ".doc"
' Send commands to Word
With WordApp
.Documents.Add
With .Selection
' Wordmacro_Starts_here
'-------------------------------------------------------------------
'Please Help ---> with HeaderFooter code below
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.Font.Name = "Arial"
Selection.Font.Size = 8
Selection.Font.Bold = wdToggle
Selection.TypeText Text:="Number ID: Number"
Selection.Font.Bold = wdToggle
Selection.TypeParagraph
If Selection.Font.Underline = wdUnderlineNone Then
Selection.Font.Underline = wdUnderlineSingle
Else
Selection.Font.Underline = wdUnderlineNone
End If
Selection.TypeText Text:="Audience: Users" & vbTab & vbTab & _
"Version: 1.0"
If Selection.HeaderFooter.IsHeader = True Then
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If
Selection.Font.Name = "Arial"
Selection.Font.Size = 8
Selection.TypeText Text:="Confidential" & vbTab & _
"(c) My Company Inc., 2005" & vbTab
NormalTemplate.AutoTextEntries("Page X of Y").Insert Where:=Selection. _
Range, RichText:=True
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
'Please Help ---> HeaderFooter code end here
'-------------------------------------------------------------------
.Font.Name = "Arial"
.Font.Size = 18
.Font.Bold = True
.TypeText Text:="Audience_Operators:" & " " & Users
.Font.Size = 12
.TypeParagraph
.TypeParagraph
.TypeParagraph
.TypeText Text:="1. Description"
.Font.Size = 10
.Font.Bold = False
.TypeParagraph
.TypeParagraph
.TypeText Text:="" & Description
.TypeParagraph
.TypeParagraph
.TypeParagraph
.Font.Size = 12
.Font.Bold = True
.TypeText Text:="2. Users"
.Font.Size = 10
.Font.Bold = False
.TypeParagraph
.TypeParagraph
.TypeText Text:="2.1" & vbTab & Users
.TypeParagraph
.TypeParagraph
.Font.Size = 12
.Font.Bold = True
.TypeText Text:="4. Flow of Events"
.Font.Size = 10
.Font.Bold = False
.TypeParagraph
.TypeParagraph
.TypeText Text:="4.1 Basic Flow"
.TypeParagraph
.TypeParagraph
.TypeText Text:="" & Steps
'------------------------------------------------------------------
Please Help
Right now the raw data wrapps in my Word report...
1. The user moves...command. 2. The user enters.... 3. The system retrieves customer account. 4. The System displays warnings messages. 5. The user selects to delete warning(s). 6. The system updates records.
What I need is code that will goto a newline when/if the numbers 1-20 are listed...
1. The user moves...command.
2. The user enters....
3. The system retrieves customer account.
4. The System displays warnings messages.
5. The user selects to delete warning(s).
6. The system updates records.
'------------------------------------------------------------------
.TypeParagraph
.TypeParagraph
End With
'Wordmarco_END_here
.ActiveDocument.SaveAs Filename:=SaveAsName
End With
Next i
' Kill the object
WordApp.Quit
Set WordApp = Nothing
' Reset status bar
Application.StatusBar = ""
MsgBox Records & " ExceltoWord documents were created and save in " & ThisWorkbook.Path
End Sub