Range.copy
Hej. Jeg har behov for at overføre 17 spørgsmål fra excel til et nyt worddokument.spørgsmål range = j8:j24, hvor af hver celle er en sætning.
Desuden skal der under hvert spørgsmål laves en tabel med mulighed for at krydse af. Det har jeg optaget i en word macro
****************************************************************
Selection.TypeParagraph
Selection.TypeParagraph
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:= _
5, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style <> "Tabel - Gitter" Then
.Style = "Tabel - Gitter"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
Selection.Borders(wdBorderTop).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderRight).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
Selection.SelectCell
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Cells.VerticalAlignment = wdCellAlignVerticalTop
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.InsertSymbol Font:="Wingdings 2", CharacterNumber:=-3933, _
Unicode:=True
Selection.MoveRight Unit:=wdCell
Selection.Borders(wdBorderTop).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderRight).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
Selection.SelectCell
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Cells.VerticalAlignment = wdCellAlignVerticalTop
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.InsertSymbol Font:="Wingdings 2", CharacterNumber:=-3933, _
Unicode:=True
Selection.MoveRight Unit:=wdCell
Selection.SelectCell
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Cells.VerticalAlignment = wdCellAlignVerticalTop
Selection.Borders(wdBorderTop).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderRight).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.InsertSymbol Font:="Wingdings 2", CharacterNumber:=-3933, _
Unicode:=True
Selection.MoveRight Unit:=wdCell
Selection.SelectCell
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Cells.VerticalAlignment = wdCellAlignVerticalTop
Selection.Borders(wdBorderTop).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderRight).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.InsertSymbol Font:="Wingdings 2", CharacterNumber:=-3933, _
Unicode:=True
Selection.MoveRight Unit:=wdCell
Selection.SelectCell
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Cells.VerticalAlignment = wdCellAlignVerticalTop
Selection.Borders(wdBorderTop).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderRight).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.InsertSymbol Font:="Wingdings 2", CharacterNumber:=-3933, _
Unicode:=True
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="yders tilfreds"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="meget tilfreds"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="tilfreds"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="utilfreds"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="meget utilfreds"
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.TypeParagraph
Selection.TypeParagraph
***************************************************************
og så skal spørgsmål 2 komme og derefter sættes endnu en tabel op.
Hvis feltet fx f23 og f24 er tomt skal der self. ikke laves en tabel.
fandt desuden et lille hint omkring hvordan data fra excel overføres fra et bestemt range.
***********************************************************'
Sub PasteToWord()
Dim AppWord As Word.Application
Set AppWord = CreateObject("Word.Application")
AppWord.Visible = True
Sheets("Sheet1").Range("A1:C10").Copy
AppWord.Documents.Add
AppWord.Selection.Paste
Application.CutCopyMode = False
Set AppWord = Nothing
End Sub
***************************************************************
Pointen er at kun have en fil, Spørgsmål.xls som behandler data og har muligheden for at oprette et spørgeskema i word ud fra de oplysninger/spørgsmål der er skrevet i excel.