Цитата: еще раз подробнее. Не догнал, слишком быстро бегаешь
Лучше с примером.
Я купил программу финансовый анализ
там формируется текстовый отчет в Word и в отчет вставляются таблицы из excel
метод судя по всему
PasteSpecial
нужно чтобы таблицы вставлялись в виде таблиц а не объектов excel и не картинок
привожу полный текст листа vba
Private word As Object
Private WordDoc As Object
[more]Function CentimetersToPoints(sm As Single) As Integer
CentimetersToPoints = sm * 29.7
End Function
Sub WordReport()
Dim word As Object, WordDoc As Object
Dim DiagName As String, TableName As String
Dim WPC As Integer, MyFile As String
Dim i As Double, qi As Double, x As Double
Dim z As Double, y As Double, w As Double, fp As Double
Dim PHidd As Double, Sname As String
If TipOtcheta = 1 Then
Sname = "Text"
Else
Sname = "TValue"
End If
Application.GoTo Reference:=("BFPrognoz")
PHidd = ActiveWorkbook.Sheets("Balance").Range("BFPrognoz").Value
ActiveWorkbook.Sheets("Plan").Columns(5 + PHidd).Hidden = True
Application.GoTo Reference:=("Progn1")
If Sheets("Balance").Range("Progn1").Value = 1 Then
If Sheets("Balance").Range("colint").Value + _
Sheets("Balance").Range("BFPrognoz").Value + 2 > 5 Then
qi = 4
GoTo 51
End If
qi = 4
End If
If Sheets("Balance").Range("Progn1").Value = 0 Then
If Sheets("Balance").Range("colint").Value + _
Sheets("Balance").Range("BFPrognoz").Value + 2 > 6 Then
qi = 4
GoTo 51
End If
qi = 4
End If
51
Set word = CreateObject("Word.application")
wdFloatOverText = 1
wdStory = 6
Set WordDoc = word.Documents.Add(, , wdFormatDocument)
word.Visible = True
word.ScreenUpdating = True
Application.ScreenUpdating = True
word.Application.Activate
If ActiveWorkbook.Sheets("Balance").Range("pformat") = 1 Then
With WordDoc.Range(Start:=word.Selection.Start, End:=WordDoc.Content.End).PageSetup
.Orientation = 0
.TopMargin = CentimetersToPoints(1.5)
.BottomMargin = CentimetersToPoints(1.5)
.LeftMargin = CentimetersToPoints(2.5)
.RightMargin = CentimetersToPoints(1)
End With
Else
With WordDoc.Range(Start:=word.Selection.Start, End:=WordDoc.Content.End).PageSetup
.Orientation = 1
.TopMargin = CentimetersToPoints(1.5)
.BottomMargin = CentimetersToPoints(1.5)
.LeftMargin = CentimetersToPoints(2.5)
.RightMargin = CentimetersToPoints(1)
End With
End If
'word.Selection.TypeParagraph
y = 1
x = 1
z = 1
For i = 1 To 1500
If ActiveWorkbook.Sheets(Sname).Cells(i, 1) = "Банкротство (начало)" Then
x = i
End If
If ActiveWorkbook.Sheets(Sname).Cells(i, 1) = "Банкротство (конец)" Then
y = i
End If
If ActiveWorkbook.Sheets(Sname).Cells(i, 1) = "Конец отчета" Then
z = i
End If
Next i
If Report.CheckBox2 = True Then
w = 1
x = z
End If
For i = 6 To x
Select Case ActiveWorkbook.Sheets(Sname).Cells(i, 1)
Case "Заголовок 1"
word.Selection.Style = WordDoc.Styles("Заголовок 1")
word.Selection.TypeText _
Text:=ActiveWorkbook.Sheets(Sname).Cells(i, 5).Text
word.Selection.TypeParagraph
Case "Заголовок 2"
word.Selection.Style = WordDoc.Styles("Заголовок 2")
word.Selection.TypeText _
Text:=ActiveWorkbook.Sheets(Sname).Cells(i, 5).Text
word.Selection.TypeParagraph
Case "Заголовок 3"
word.Selection.Style = WordDoc.Styles("Заголовок 3")
word.Selection.TypeText _
Text:=ActiveWorkbook.Sheets(Sname).Cells(i, 5).Text
word.Selection.TypeParagraph
Case "Альбомная"
wdSectionBreakNextPage = 2
WordDoc.Range(Start:=word.Selection.Start, End:=word.Selection.Start). _
InsertBreak Type:=wdSectionBreakNextPage
word.Selection.Start = word.Selection.Start + 1
With WordDoc.Range(Start:=word.Selection.Start, End:=WordDoc.Content.End).PageSetup
.Orientation = 1
End With
Case "Книжная"
wdSectionBreakNextPage = 2
WordDoc.Range(Start:=word.Selection.Start, End:=word.Selection.Start). _
InsertBreak Type:=wdSectionBreakNextPage
word.Selection.Start = word.Selection.Start + 1
With WordDoc.Range(Start:=word.Selection.Start, End:=WordDoc.Content.End).PageSetup
.Orientation = 0
End With
Case "Диаграмма"
DiagName = ActiveWorkbook.Sheets(Sname).Cells(i, 2)
Sheets(DiagName).Select
ActiveChart.ChartArea.Copy
word.Selection.TypeParagraph
' вставляем диаграмму
word.Selection.PasteSpecial Link:=False, _
DataType:=wdPasteOLEObject, _
Placement:=0, _
DisplayAsIcon:=False
word.Selection.TypeParagraph
Case "Формула"
word.Selection.TypeText _
Text:=ActiveWorkbook.Sheets(Sname).Cells(i, 5).Text
WPC = WordDoc.Paragraphs.Count
word.ActiveDocument.Paragraphs(WPC).Range.Select
With word.Selection.ParagraphFormat
wdAlignParagraphJustify = 1
.Alignment = wdAlignParagraphJustify
.FirstLineIndent = CentimetersToPoints(1#)
End With
With word.Selection
.Font.Italic = True
End With
word.Selection.MoveRight Unit:=1, Count:=1
word.Selection.TypeParagraph
word.ActiveDocument.Paragraphs(WPC + 1).Range.Select
Case "Обычный"
word.Selection.Style = WordDoc.Styles("Обычный")
word.Selection.TypeText _
Text:=ActiveWorkbook.Sheets(Sname).Cells(i, 5).Text
WPC = WordDoc.Paragraphs.Count
word.ActiveDocument.Paragraphs(WPC).Range.Select
With word.Selection.ParagraphFormat
wdAlignParagraphJustify = 3
.Alignment = wdAlignParagraphJustify
.FirstLineIndent = CentimetersToPoints(0.7)
End With
word.Selection.MoveRight Unit:=1, Count:=1
word.Selection.TypeParagraph
word.ActiveDocument.Paragraphs(WPC + 1).Range.Select
With word.Selection.ParagraphFormat
.FirstLineIndent = CentimetersToPoints(0#)
End With
Case "Рисунок"
' наименование таблицы
WPC = WordDoc.Paragraphs.Count
word.ActiveDocument.Paragraphs(WPC).Range.Select
With word.Selection.ParagraphFormat
wdAlignParagraphCenter = 1
.Alignment = wdAlignParagraphCenter
End With
With word.Selection
.Font.Bold = True
End With
TableName = ActiveWorkbook.Sheets(Sname).Cells(i, 2)
word.Selection.TypeText _
Text:=ActiveWorkbook.Sheets(Sname).Cells(i, 5).Text
With word.Selection
.Font.Bold = False
End With
word.Selection.TypeParagraph
' надпись (рисунок №)
word.Selection.TypeParagraph
word.ActiveDocument.Paragraphs(WPC + 1).Range.Select
With word.Selection.ParagraphFormat
wdAlignParagraphRight = 2
.Alignment = wdAlignParagraphRight
End With
TableName = ActiveWorkbook.Sheets(Sname).Cells(i, 2)
word.Selection.TypeText _
Text:=ActiveWorkbook.Sheets(Sname).Cells(i, 4).Text
Application.GoTo Reference:=(TableName)
Selection.Copy
' вставляем картинку ' 4 - формат bmp, 3 - пять периодов максимум
word.Selection.PasteSpecial Link:=False, _
DataType:=wdPasteOLEObject, _
Placement:=0, _
DisplayAsIcon:=False
word.Selection.TypeParagraph
Case "Приложение2"
If Report.CheckBox1 = True Then
On Error GoTo 10
MyFile = ActiveWorkbook.Sheets("Balance").Range("PrilFile").Value
Set Pril = CreateObject("Word.Application")
Pril.Documents.Open Filename:=MyFile, ReadOnly:=True
With Pril
.ActiveDocument.Select
.Selection.Copy
End With
word.Selection.Paste
End If
10
word.Application.Activate
20
Case "Разрыв"
wdPageBreak = 7
word.Selection.InsertBreak Type:=wdPageBreak
End Select
Next i
' в случае отсутствия главы о банкротстве.
If w = 1 Then GoTo 50
For i = y To z
Select Case ActiveWorkbook.Sheets(Sname).Cells(i, 1)
Case "Заголовок 1"
word.Selection.Style = WordDoc.Styles("Заголовок 1")
word.Selection.TypeText _
Text:=ActiveWorkbook.Sheets(Sname).Cells(i, 5).Text
word.Selection.TypeParagraph
Case "Заголовок 2"
word.Selection.Style = WordDoc.Styles("Заголовок 2")
word.Selection.TypeText _
Text:=ActiveWorkbook.Sheets(Sname).Cells(i, 5).Text
word.Selection.TypeParagraph
Case "Заголовок 3"
word.Selection.Style = WordDoc.Styles("Заголовок 3")
word.Selection.TypeText _
Text:=ActiveWorkbook.Sheets(Sname).Cells(i, 5).Text
word.Selection.TypeParagraph
Case "Альбомная"
wdSectionBreakNextPage = 2
WordDoc.Range(Start:=word.Selection.Start, End:=word.Selection.Start). _
InsertBreak Type:=wdSectionBreakNextPage
word.Selection.Start = word.Selection.Start + 1
With WordDoc.Range(Start:=word.Selection.Start, End:=WordDoc.Content.End).PageSetup
.Orientation = 1
End With
Case "Книжная"
wdSectionBreakNextPage = 2
WordDoc.Range(Start:=word.Selection.Start, End:=word.Selection.Start). _
InsertBreak Type:=wdSectionBreakNextPage
word.Selection.Start = word.Selection.Start + 1
With WordDoc.Range(Start:=word.Selection.Start, End:=WordDoc.Content.End).PageSetup
.Orientation = 0
End With
Case "Диаграмма"
DiagName = ActiveWorkbook.Sheets(Sname).Cells(i, 2)
Sheets(DiagName).Select
ActiveChart.ChartArea.Copy
word.Selection.TypeParagraph
' вставляем диаграмму
word.Selection.PasteSpecial Link:=False, _
DataType:=3, _
Placement:=0, _
DisplayAsIcon:=False
word.Selection.TypeParagraph
Case "Формула"
word.Selection.TypeText _
Text:=ActiveWorkbook.Sheets(Sname).Cells(i, 5).Text
WPC = WordDoc.Paragraphs.Count
word.ActiveDocument.Paragraphs(WPC).Range.Select
With word.Selection.ParagraphFormat
wdAlignParagraphJustify = 3
.Alignment = wdAlignParagraphJustify
.FirstLineIndent = CentimetersToPoints(1#)
End With
word.Selection.MoveRight Unit:=1, Count:=1
word.Selection.TypeParagraph
word.ActiveDocument.Paragraphs(WPC + 1).Range.Select
Case "Обычный"
word.Selection.Style = WordDoc.Styles("Обычный")
word.Selection.TypeText _
Text:=ActiveWorkbook.Sheets(Sname).Cells(i, 5).Text
WPC = WordDoc.Paragraphs.Count
word.ActiveDocument.Paragraphs(WPC).Range.Select
With word.Selection.ParagraphFormat
wdAlignParagraphJustify = 3
.Alignment = wdAlignParagraphJustify
.FirstLineIndent = CentimetersToPoints(0.7)
End With
word.Selection.MoveRight Unit:=1, Count:=1
word.Selection.TypeParagraph
word.ActiveDocument.Paragraphs(WPC + 1).Range.Select
With word.Selection.ParagraphFormat
.FirstLineIndent = CentimetersToPoints(0#)
End With
Case "Рисунок"
' наименование таблицы
WPC = WordDoc.Paragraphs.Count
word.ActiveDocument.Paragraphs(WPC).Range.Select
With word.Selection.ParagraphFormat
wdAlignParagraphCenter = 1
.Alignment = wdAlignParagraphCenter
End With
With word.Selection
.Font.Bold = True
End With
TableName = ActiveWorkbook.Sheets(Sname).Cells(i, 2)
word.Selection.TypeText _
Text:=ActiveWorkbook.Sheets(Sname).Cells(i, 5).Text
With word.Selection
.Font.Bold = False
End With
word.Selection.TypeParagraph
' надпись (рисунок №)
word.Selection.TypeParagraph
word.ActiveDocument.Paragraphs(WPC + 1).Range.Select
With word.Selection.ParagraphFormat
wdAlignParagraphRight = 2
.Alignment = wdAlignParagraphRight
End With
TableName = ActiveWorkbook.Sheets(Sname).Cells(i, 2)
word.Selection.TypeText _
Text:=ActiveWorkbook.Sheets(Sname).Cells(i, 4).Text
Application.GoTo Reference:=(TableName)
Selection.Copy
' вставляем картинку ' 4 - формат bmp, 3 - пять периодов максимум
word.Selection.TypeParagraph
word.Selection.PasteSpecial Link:=False, _
DataType:=qi, _
Placement:=0, _
DisplayAsIcon:=False
word.Selection.TypeParagraph
Case "Приложение2"
If Report.CheckBox1 = True Then
On Error GoTo 40
MyFile = ActiveWorkbook.Sheets("Balance").Range("PrilFile").Value
Set Pril = CreateObject("Word.Application")
Pril.Documents.Open Filename:=MyFile, ReadOnly:=True
With Pril
.ActiveDocument.Select
.Selection.Copy
End With
word.Selection.Paste
End If
40
Case "Разрыв"
wdPageBreak = 7
word.Selection.InsertBreak Type:=wdPageBreak
End Select
Next i
50
' осуществляем переход на начало первой страницы
With word.Selection
.GoTo What:=1, Count:=1
End With
wdPageBreak = 7
word.Selection.InsertBreak Type:=wdPageBreak
'первая страница
If ActiveWorkbook.Sheets("Balance").Range("pformat") = 1 Then
fp = 22
Else
fp = 15
End If
WordDoc.Application.Browser.Previous
For i = 1 To fp
word.Selection.TypeParagraph
Next i
With word.Selection
.Style = WordDoc.Styles("Обычный")
.Font.name = "Arial"
.Font.Size = 16
.Font.Bold = True
End With
If TipOtcheta = 1 Then
word.Selection.TypeText Text:="АНАЛИЗ ФИНАНСОВОГО СОСТОЯНИЯ"
Else
word.Selection.TypeText Text:="ОТЧЕТ ОБ ОЦЕНКЕ СТОИМОСТИ"
End If
word.Selection.ParagraphFormat.Alignment = 1
word.Selection.TypeParagraph
word.Selection.TypeText _
Text:=ActiveWorkbook.Sheets(Sname).Cells(3, 5).Text
wdPageBreak = 7
word.Selection.InsertBreak Type:=wdPageBreak
With word.Selection
.GoTo What:=1, Count:=2
End With
' построение оглавления
With WordDoc
.TablesOfContents.Add Range:=word.Selection.Range, RightAlignPageNumbers:= _
True, UseHeadingStyles:=True, UpperHeadingLevel:=1, _
LowerHeadingLevel:=3, IncludePageNumbers:=True, AddedStyles:=""
.TablesOfContents(1).TabLeader = wdTabLeaderDots
.TablesOfContents.Format = wdIndexIndent
End With
' колонтитулы
word.ActiveWindow.ActivePane.View.SeekView = 9
With word.Selection.Font
.Underline = 1
.name = "Arial"
.Size = 8
.ColorIndex = 15
.Bold = True
End With
word.Selection.TypeText _
Text:="Анализ проведен " & ActiveWorkbook.Sheets(Sname).Cells(3, 1).Text & " стр. № "
word.Selection.Fields.Add Range:=word.Selection.Range, Type:=33
word.Selection.ParagraphFormat.Alignment = 2
word.ActiveWindow.ActivePane.View.SeekView = 10
With word.Selection.Font
.Underline = wdUnderlineSingle
.name = "Arial"
.Size = 8
.ColorIndex = 15
.Bold = True
End With
word.Selection.TypeText _
Text:=ActiveWorkbook.Sheets(Sname).Cells(4, 1).Text
word.Selection.ParagraphFormat.Alignment = 2
word.ActiveWindow.ActivePane.View.SeekView = 0
For i = 2 To 14
Sheets(i).Activate
Sheets(i).Range(Cells(2, 1), Cells(2, 1)).Select
Next i
ActiveWorkbook.Sheets("Plan").Columns(5 + PHidd).Hidden = False
On Error Resume Next
word.Documents.Save
On Error Resume Next
word.Application.Activate
On Error Resume Next
WordDoc.Close
Set WordDoc = Nothing
Set Pril = Nothing
Set word = Nothing
ActiveWorkbook.Activate
End Sub
Sub WordReport367()
Dim word As Object, WordDoc As Object
Dim DiagName As String, TableName As String
Dim WPC As Integer, MyFile As String
Dim i As Double, qi As Double, x As Double
Dim z As Double, y As Double, w As Double, fp As Double
Application.GoTo Reference:=("Progn1")
If Sheets("Balance").Range("Progn1").Value = 1 Then
If Sheets("Balance").Range("colint").Value + _
Sheets("Balance").Range("BFPrognoz").Value + 2 > 5 Then
qi = 4
GoTo 51
End If
qi = 3
End If
If Sheets("Balance").Range("Progn1").Value = 0 Then
If Sheets("Balance").Range("colint").Value + _
Sheets("Balance").Range("BFPrognoz").Value + 2 > 6 Then
qi = 4
GoTo 51
End If
qi = 3
End If
51
Set word = CreateObject("Word.application")
wdFloatOverText = 1
wdStory = 6
Set WordDoc = word.Documents.Add(, , wdFormatDocument)
word.Visible = True
word.ScreenUpdating = True
Application.ScreenUpdating = True
word.Application.Activate
If ActiveWorkbook.Sheets("Balance").Range("pformat") = 1 Then
With WordDoc.Range(Start:=word.Selection.Start, End:=WordDoc.Content.End).PageSetup
.Orientation = 0
.TopMargin = CentimetersToPoints(1.5)
.BottomMargin = CentimetersToPoints(1.5)
.LeftMargin = CentimetersToPoints(2.5)
.RightMargin = CentimetersToPoints(1)
End With
Else
With WordDoc.Range(Start:=word.Selection.Start, End:=WordDoc.Content.End).PageSetup
.Orientation = 1
.TopMargin = CentimetersToPoints(2.5)
.BottomMargin = CentimetersToPoints(1)
.LeftMargin = CentimetersToPoints(1.5)
.RightMargin = CentimetersToPoints(1.5)
End With
End If
'word.Selection.TypeParagraph
For i = 1 To 1500
If ActiveWorkbook.Sheets("Text367").Cells(i, 1) = "Конец отчета" Then
x = i
End If
Next i
For i = 6 To x
Select Case ActiveWorkbook.Sheets("Text367").Cells(i, 1)
Case "Заголовок 1"
word.Selection.Style = WordDoc.Styles("Заголовок 1")
word.Selection.TypeText _
Text:=ActiveWorkbook.Sheets("Text367").Cells(i, 4).Text
word.Selection.TypeParagraph
Case "Заголовок 2"
word.Selection.Style = WordDoc.Styles("Заголовок 2")
word.Selection.TypeText _
Text:=ActiveWorkbook.Sheets("Text367").Cells(i, 4).Text
word.Selection.TypeParagraph
Case "Заголовок 3"
word.Selection.Style = WordDoc.Styles("Заголовок 3")
word.Selection.TypeText _
Text:=ActiveWorkbook.Sheets("Text367").Cells(i, 4).Text
word.Selection.TypeParagraph
Case "Альбомная"
wdSectionBreakNextPage = 2
WordDoc.Range(Start:=word.Selection.Start, End:=word.Selection.Start). _
InsertBreak Type:=wdSectionBreakNextPage
word.Selection.Start = word.Selection.Start + 1
With WordDoc.Range(Start:=word.Selection.Start, End:=WordDoc.Content.End).PageSetup
.Orientation = 1
End With
Case "Книжная"
wdSectionBreakNextPage = 2
WordDoc.Range(Start:=word.Selection.Start, End:=word.Selection.Start). _
InsertBreak Type:=wdSectionBreakNextPage
word.Selection.Start = word.Selection.Start + 1
With WordDoc.Range(Start:=word.Selection.Start, End:=WordDoc.Content.End).PageSetup
.Orientation = 0
End With
Case "Диаграмма"
DiagName = ActiveWorkbook.Sheets("Text367").Cells(i, 2)
Sheets(DiagName).Select
ActiveChart.ChartArea.Copy
word.Selection.TypeParagraph
' вставляем диаграмму
word.Selection.PasteSpecial Link:=False, _
DataType:=3, _
Placement:=0, _
DisplayAsIcon:=False
word.Selection.TypeParagraph
Case "Формула"
word.Selection.TypeText _
Text:=ActiveWorkbook.Sheets("Text367").Cells(i, 4).Text
WPC = WordDoc.Paragraphs.Count
word.ActiveDocument.Paragraphs(WPC).Range.Select
With word.Selection.ParagraphFormat
wdAlignParagraphJustify = 1
.Alignment = wdAlignParagraphJustify
.FirstLineIndent = CentimetersToPoints(1#)
End With
With word.Selection
.Font.Italic = True
End With
word.Selection.MoveRight Unit:=1, Count:=1
word.Selection.TypeParagraph
word.ActiveDocument.Paragraphs(WPC + 1).Range.Select
Case "Обычный"
word.Selection.Style = WordDoc.Styles("Обычный")
word.Selection.TypeText _
Text:=ActiveWorkbook.Sheets("Text367").Cells(i, 4).Text
WPC = WordDoc.Paragraphs.Count
word.ActiveDocument.Paragraphs(WPC).Range.Select
With word.Selection.ParagraphFormat
wdAlignParagraphJustify = 3
.Alignment = wdAlignParagraphJustify
.FirstLineIndent = CentimetersToPoints(0.7)
End With
word.Selection.MoveRight Unit:=1, Count:=1
word.Selection.TypeParagraph
word.ActiveDocument.Paragraphs(WPC + 1).Range.Select
With word.Selection.ParagraphFormat
.FirstLineIndent = CentimetersToPoints(0#)
End With
Case "Рисунок"
' наименование таблицы
WPC = WordDoc.Paragraphs.Count
word.ActiveDocument.Paragraphs(WPC).Range.Select
With word.Selection.ParagraphFormat
wdAlignParagraphCenter = 1
.Alignment = wdAlignParagraphCenter
End With
With word.Selection
.Font.Bold = True
End With
TableName = ActiveWorkbook.Sheets("Text367").Cells(i, 2)
word.Selection.TypeText _
Text:=ActiveWorkbook.Sheets("Text367").Cells(i, 4).Text
With word.Selection
.Font.Bold = False
End With
word.Selection.TypeParagraph
' надпись (рисунок №)
word.Selection.TypeParagraph
word.ActiveDocument.Paragraphs(WPC + 1).Range.Select
With word.Selection.ParagraphFormat
wdAlignParagraphRight = 2
.Alignment = wdAlignParagraphRight
End With
TableName = ActiveWorkbook.Sheets("Text367").Cells(i, 2)
word.Selection.TypeText _
Text:=ActiveWorkbook.Sheets("Text367").Cells(i, 4).Text
Application.GoTo Reference:=(TableName)
Selection.Copy
' вставляем картинку ' 4 - формат bmp, 3 - пять периодов максимум
word.Selection.TypeParagraph
word.Selection.TypeParagraph
Case "Приложение2"
If Report.CheckBox1 = True Then
On Error GoTo 10
MyFile = ActiveWorkbook.Sheets("Balance").Range("PrilFile").Value
Set Pril = CreateObject("Word.Application")
Pril.Documents.Open Filename:=MyFile, ReadOnly:=True
With Pril
.ActiveDocument.Select
.Selection.Copy
End With
word.Selection.Paste
End If
GoTo 20
10
MsgBox ("Файл приложения к отчету выбран некорректно. Отчет будет построен без приложения")
20
Case "Разрыв"
wdPageBreak = 7
word.Selection.InsertBreak Type:=wdPageBreak
End Select
Next i
' осуществляем переход на начало первой страницы
With word.Selection
.GoTo What:=1, Count:=1
End With
wdPageBreak = 7
word.Selection.InsertBreak Type:=wdPageBreak
'первая страница
If ActiveWorkbook.Sheets("Balance").Range("pformat") = 1 Then
fp = 22
Else
fp = 15
End If
WordDoc.Application.Browser.Previous
For i = 1 To fp
word.Selection.TypeParagraph
Next i
With word.Selection
.Style = WordDoc.Styles("Обычный")
.Font.name = "Arial"
.Font.Size = 16
.Font.Bold = True
End With
word.Selection.TypeText Text:="АНАЛИЗ ФИНАНСОВОГО СОСТОЯНИЯ"
word.Selection.ParagraphFormat.Alignment = 1
word.Selection.TypeParagraph
word.Selection.TypeText _
Text:=ActiveWorkbook.Sheets("Text367").Cells(3, 4).Text
wdPageBreak = 7
word.Selection.InsertBreak Type:=wdPageBreak
With word.Selection
.GoTo What:=1, Count:=2
End With
' построение оглавления
With WordDoc
.TablesOfContents.Add Range:=word.Selection.Range, RightAlignPageNumbers:= _
True, UseHeadingStyles:=True, UpperHeadingLevel:=1, _
LowerHeadingLevel:=3, IncludePageNumbers:=True, AddedStyles:=""
.TablesOfContents(1).TabLeader = wdTabLeaderDots
.TablesOfContents.Format = wdIndexIndent
End With
' колонтитулы
word.ActiveWindow.ActivePane.View.SeekView = 9
With word.Selection.Font
.Underline = 1
.name = "Arial"
.Size = 8
.ColorIndex = 15
.Bold = True
End With
word.Selection.TypeText _
Text:="Анализ проведен " & ActiveWorkbook.Sheets("Text367").Cells(3, 1).Text & " стр. № "
word.Selection.Fields.Add Range:=word.Selection.Range, Type:=33
word.Selection.ParagraphFormat.Alignment = 2
word.ActiveWindow.ActivePane.View.SeekView = 10
With word.Selection.Font
.Underline = wdUnderlineSingle
.name = "Arial"
.Size = 8
.ColorIndex = 15
.Bold = True
End With
word.Selection.TypeText _
Text:=ActiveWorkbook.Sheets("Text367").Cells(4, 1).Text
word.Selection.ParagraphFormat.Alignment = 2
word.ActiveWindow.ActivePane.View.SeekView = 0
For i = 2 To 14
Sheets(i).Activate
Sheets(i).Range(Cells(2, 1), Cells(2, 1)).Select
Next i
On Error Resume Next
word.Documents.Save
On Error Resume Next
WordDoc.Close
Set WordDoc = Nothing
Set Pril = Nothing
Set word = Nothing
ActiveWorkbook.Activate
End Sub
[/more]