You are on page 1of 5

Option Explicit

Dim wb As Workbook
Dim ws As Worksheet, ws2 As Worksheet
Dim applWord As Object
Dim docWord As Object
Sub idiuword()
Range("a5:a500").FormulaR1C1 =
"=IF(TRIM(RC[1])<>"""",COUNTA(R5C2:RC[1])&""."","""")"
'Range("A2").Select
'Dim wb As Workbook
'Dim ws As Worksheet, ws2 As Worksheet
Dim lastrow As Integer
Dim rowidx As Integer
Set wb = ActiveWorkbook
'Copy to a new sheet
'ActiveSheet.Copy After:=Sheets(Sheets.Count)
Set ws = Sheets(Sheets.Count)
With wb
With ws
'.Activate: .Select 'really only need one or the other
lastrow = Range("k32000").End(xlUp).Row 'Find the last row in col k
'Loop each row from the bottom up
For rowidx = lastrow To 2 Step -1
Range("k" & rowidx).Select 'only needed for debug
'If this Col k <> the one above it
If Range("k" & rowidx) <> Range("k" & rowidx - 1) Then
'Insert Row
Range("k" & rowidx).EntireRow.Insert (xlDown)
'Copy Firm to Header
Range("k" & rowidx).Offset(0, -2).Value = Range("k" & rowidx).Offset(1, 0).Value
Range("k" & rowidx).Offset(0, -2).Font.Bold = True
Range("k" & rowidx).Offset(0, -2).HorizontalAlignment = xlCenter
Range(Cells(rowidx, 1), Cells(rowidx, 10)).MergeCells = True
Else
'skip it
End If
Next rowidx
End With
End With
Dim lastrow1 As Long

On Error Resume Next


lastrow1 = Range("B65536").End(xlUp).Row ' or + 1
Cells(lastrow1 + 1, 1) = "REKAPITULACIJA"
Cells(lastrow1 + 1, 1).Font.Bold = True
Cells(lastrow1 + 1, 1).Font.Size = 14
Range(Cells(lastrow1 + 1, 1), Cells(lastrow1 + 1, 6)).MergeCells = True
Range("L6:N6").Copy Range("G" & lastrow1 + 1)
Range(Cells(lastrow1 + 1, 9), Cells(lastrow1 + 1, 10)).MergeCells = True
'Range(Cells(lastrow1 + 1, 9), Cells(lastrow1 + 1, 10)).WrapText = True

Range(Cells(lastrow1 + 1, 1), Cells(lastrow1 + 1, 10)).VerticalAlignment = xlCenter


Cells(lastrow1 + 1, 7).HorizontalAlignment = xlCenter
Columns("K:N").EntireColumn.Delete
ActiveSheet.Rows(lastrow1 + 2 & ":" & ActiveSheet.Rows.Count).ClearContents
'With Range(Cells(lastrow1 + 1, 1), Cells(lastrow1 + 1, 10)).Borders
With Range("A4:J" & lastrow1 + 1).Borders
.ColorIndex = xlAutomatic
.LineStyle = xlContinuous
.Weight = xlThin
End With
With Range("a4:J4")
.Interior.ColorIndex = 15
End With
Dim rng As Range
Dim c As Range
Set rng = Range("H6:H500", "I6:I500")
For Each c In rng
' c = Replace(c, Chr(8), "") 'Backspace
'c = Replace(c, Chr(9), "") 'Tab
'c = Replace(c, Chr(10), "") 'Line feed
c = Replace(c, Chr(13), "") 'Carriage Return
'c = Replace(c, Chr(127), "") 'Spaecial Space
Next c

'Dim applWord As Object


'Dim docWord As Object
Dim tbl As Table
'set the Application object variable to create a new instance of Word:
Set applWord = CreateObject("Word.Application")

'make the Word window visible:


applWord.Visible = True
'maximize Word window:
'replaced the Word's built-in constant wdWindowStateMaximize with its numerical value 1.
applWord.WindowState = 1
'opens an existing word document from a defined folder:
Set docWord = applWord.Documents.Add(Environ("USERPROFILE") & "\My
Documents\01 kontrole\analiza_kontrola.dot")
'(Application.ActiveWorkbook.Path & "\" & "\analiza_kontrola.dot")
Set ws2 = ThisWorkbook.Sheets("akt")
'Set ws1 = ThisWorkbook.Sheets("analiza")
Dim rngexcel As Range
'Dim lastrow2 As Long
'lastrow2 = ws1.Range("B65536").End(xlUp).Row ' or + 1
Set rngexcel = ActiveSheet.Range("A4:J" & lastrow1 + 1)
With docWord.Content
.Bookmarks("brojakta1").Range.Text = ws2.Range("D7").Value
.Bookmarks("datumakta1").Range.Text = ws2.Range("E8").Value
.Bookmarks("mjigod5").Range.Text = ws2.Range("G19").Value
.Bookmarks("mjigod6").Range.Text = ws2.Range("G19").Value
.Bookmarks("mjigod7").Range.Text = ws2.Range("G19").Value
.Bookmarks("mjigod8").Range.Text = UCase(ws2.Range("G19").Value)
End With
docWord.Bookmarks("tabela1").Range.Select
rngexcel.Copy
applWord.Selection.PasteSpecial 'Link:=False, DataType:=1, Placement:=0,
DisplayAsIcon:=False
Set tbl = docWord.Tables(1)
With tbl
.Rows.HeightRule = wdRowHeightAuto
.Rows(1).HeadingFormat = True
.Range.Font.Size = 12
.Range.Font.Name = "Times New Roman"
.Rows.Alignment = wdAlignRowCenter
.Range.Cells.VerticalAlignment = wdCellAlignVerticalCenter
.Range.LanguageID = wdCroatian
End With
End Sub

Sub asd()
Dim tbl1 As Table
Dim tbl2 As Table
'set the Application object variable to create a new instance of Word:
Set applWord = CreateObject("Word.Application")
'make the Word window visible:
applWord.Visible = True
'maximize Word window:
'replaced the Word's built-in constant wdWindowStateMaximize with its numerical value 1.
applWord.WindowState = 1
'opens an existing word document from a defined folder:
Set docWord = applWord.Documents.Add(Environ("USERPROFILE") & "\My
Documents\01 kontrole\analiza_kontrola.dot")
'(Application.ActiveWorkbook.Path & "\" & "\analiza_kontrola.dot")
'Set ws2 = ThisWorkbook.Sheets("akt")
'Set ws1 = ThisWorkbook.Sheets("analiza")
Dim rngexcel As Range
Set rngexcel = ActiveWorkbook.Sheets("rekapitulacija1").Range("B5:K8")
docWord.Bookmarks("tabela2").Range.Select
rngexcel.Copy
applWord.Selection.Paste 'Link:=False, DataType:=1, Placement:=0,
DisplayAsIcon:=False
Set tbl1 = docWord.Tables(1)
With tbl1
.Rows.HeightRule = wdRowHeightAuto
.Range.Font.Size = 12
.Range.Font.Name = "Times New Roman"
.Rows.Alignment = wdAlignRowCenter
.Range.Cells.VerticalAlignment = wdCellAlignVerticalCenter
.Range.LanguageID = wdCroatian
End With
Dim rngexcel1 As Range
Set rngexcel1 = ActiveWorkbook.Sheets("rekapitulacija1").Range("B11:L20")
docWord.Bookmarks("tabela3").Range.Select
rngexcel1.Copy
applWord.Selection.Paste 'Link:=False, DataType:=1, Placement:=0,
DisplayAsIcon:=False

Set tbl2 = docWord.Tables(2)


With tbl2
.Rows.HeightRule = wdRowHeightAuto
.Range.Font.Size = 12
.Range.Font.Name = "Times New Roman"
.Rows.Alignment = wdAlignRowCenter
.Range.Cells.VerticalAlignment = wdCellAlignVerticalCenter
.Range.LanguageID = wdCroatian
End With
End Sub

You might also like