Avatar billede kristiankogut Nybegynder
20. marts 2010 - 14:50 Der er 9 kommentarer og
1 løsning

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.
Avatar billede supertekst Ekspert
20. marts 2010 - 15:41 #1
Alternativ:

Du kan faktisk anvende brevfletning - Excel-filen som datakilde & word-fil som hoveddok. med en tabel - flet til adresseliste.
Avatar billede kristiankogut Nybegynder
20. marts 2010 - 18:54 #2
Det skal være i en fil,  altså en macro der opretter et word dokument
Avatar billede supertekst Ekspert
21. marts 2010 - 14:31 #3
VBA-koden indlægges i Excel-filen:

Dim sti As String
Dim spDoc As Object, ræk As Integer, spørgsmål As String

Const spKolonne = "J"
Const startRæk = 8
Const slutRæk = 24
Public Sub opbygSpørgeskema()
    sti = findSti
    åbnSpDoc
     
    For ræk = startRæk To slutRæk
        spørgsmål = hentSpørgsmål(ræk)
       
        overførTilDoc spørgsmål
        opbygTabel
    Next ræk
   
    lukSpDoc
End Sub
Private Function findSti()
    findSti = ActiveWorkbook.Path
    If Right(findSti, 1) <> "\" Then
        findSti = findSti + "\"
    End If
End Function
Private Sub åbnSpDoc()
    Set spDoc = CreateObject("Word.Application")
    With spDoc
Rem        .Visible = True
        .documents.Add
    End With
End Sub
Private Sub lukSpDoc()
    spDoc.ActiveDocument.SaveAs Filename:=sti + "spørgeSkema.doc"
    spDoc.ActiveDocument.Close
    spDoc.Application.Quit
    Set spDoc = Nothing
End Sub
Private Function hentSpørgsmål(ræk As Integer)
    hentSpørgsmål = ActiveSheet.Range(spKolonne & CStr(ræk))
End Function
Private Sub overførTilDoc(spørgsmål)
    spDoc.Selection.TypeText Text:=spørgsmål
End Sub
Private Sub opbygTabel()
Dim f As Byte

    With spDoc
        .Application.ScreenUpdating = False
       
        .Selection.TypeParagraph
        .Selection.TypeParagraph
       
        .ActiveDocument.Tables.Add Range:=.Selection.Range, NumRows:=2, NumColumns:= _
            5, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
            wdAutoFitFixed
       
        For f = 1 To 5
            .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
        Next f
       
        .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
    End With
End Sub
Avatar billede supertekst Ekspert
04. april 2010 - 15:11 #4
Noget nyt?
Avatar billede kristiankogut Nybegynder
05. juni 2010 - 22:12 #5
Jeg kigger lige på den en af de nærmeste dage.. ser godt ud.
Avatar billede supertekst Ekspert
05. juni 2010 - 23:17 #6
ok
Avatar billede kristiankogut Nybegynder
06. juni 2010 - 12:58 #7
Det var lige det jeg skulle bruge.. Mange tak.
Avatar billede kristiankogut Nybegynder
06. juni 2010 - 12:59 #8
Hvis du vil smide et svar så du kan få lidt points..
Avatar billede supertekst Ekspert
06. juni 2010 - 13:54 #9
Selv tak - og et svar...
Avatar billede supertekst Ekspert
08. juni 2010 - 23:12 #10
PS: Hvis jeg skal have points - så må du jo accepterer mit svar - ellers luk spørgsmålet og tag selv points.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester