2012-05-09 10 views
1

スプレッドシートから(辞書アドオンを使用して)ワードドキュメント内の設定ブックマークにデータを転送する方法を探しています。辞書とブックマークを使用してExcelからWordにデータを転送する

スプレッドシート内のデータの各行を繰り返して、現在のブックマークにデータを埋め込んだ後、以前のブックマークを削除してから、ループを続ける必要があります。

しかし、Excelのデータをブックマークに1回だけ渡すだけで誰でも助けてくれれば、本当に感謝しています。そこから簡単に実行できます。ここで

は、私がこれまでに(私は、コードの下部にこだわっ右だ!)したものである:

Dim columnLocations As New Dictionary 
Dim bookmarkOrder As New Dictionary 
Dim solutionWorkbook As Workbook 

Sub Main() 
    Set solutionWorkbook = ActiveWorkbook 

    columnLocations.RemoveAll 
    bookmarkOrder.RemoveAll 

    Call PopulateColumnLocations 
    Call PopulateBookmarkMappings 
    Call DictionaryData 
End Sub 

Sub PopulateColumnLocations() 
    'Loop through row1 to populate dictionary. key = header name, value = column number 
    Sheets("Data").Select 
    For Each cell In solutionWorkbook.Worksheets("Data").Range("A10", Range("A10").End(xlToRight)).Cells 
    columnLocations.Add Trim(cell.Value), cell.Column 
    Next 
End Sub 

Sub PopulateBookmarkMappings() 
    'Loop through row1 to populate dictionary. key = header name, value = collumn number 
    Sheets("Mappings").Select 
    Dim Var As Object 
    Dim Key As Object 

    For Each cell In solutionWorkbook.Worksheets("Mappings").Range("A2", Range("A2").End(xlDown)).Cells 
    Debug.Print Cells(cell.Row, 2).Value 
    Debug.Print cell.Value 
    bookmarkOrder.Add Trim(cell.Value), Cells(cell.Row, 2).Value 'the 2 is the column which has the bookmark name in 
    Next 
End Sub 

Sub DictionaryData() 
    Sheets("Data").Select 
    Dim count As Integer 
    count = 1 
    'Loop through all rows in input data sheet 
    For Each cell In solutionWorkbook.Worksheets("Data").Range("A11", Range("A11").End(xlDown)).Cells 
    Dim TweetSummary As String 
    TweetSummary = solutionWorkbook.Sheets("Data").Cells(cell.Row, columnLocations.Item("Summary")).Value 

    Dim TweetDate As String 
    TweetDate = solutionWorkbook.Sheets("Data").Cells(cell.Row, columnLocations.Item("Date")).Value 

    Dim TweetURL As String 
    TweetURL = solutionWorkbook.Sheets("Data").Cells(cell.Row, columnLocations.Item("URL")).Value 

    Dim TweetFollowers As String 
    TweetFollowers = solutionWorkbook.Sheets("Data").Cells(cell.Row, columnLocations.Item("Twitter Followers")).Value 

    Dim TweetFollowing As String 
    TweetFollowing = solutionWorkbook.Sheets("Data").Cells(cell.Row, columnLocations.Item("Twitter Following")).Value 

    Dim TweetTweets As String 
    TweetTweets = solutionWorkbook.Sheets("Data").Cells(cell.Row, columnLocations.Item("Twitter Tweets")).Value 

    Next 
End Sub 

Sub Worddoc() 
    Dim LaunchWord As Object 
    Dim tweetWord As Object 
    Dim Path As String 
    Dim tBookmark As Bookmark 
    Path = solutionWorkbook.Path & "\B_watch_social_twitter_template.dot" 

    Set LaunchWord = CreateObject("Word.Application") 
    Set tweetWord = LaunchWord.Documents.Add(Path) 

    tweetWord.Select 

''IM STUCK HERE!!! 
End Sub 
+0

Excelに複数の行のデータがあるように見えますが、Wordテンプレートがどのように設定されているか、どのように入力するかは明確ではありません。 'CreateTemplate'では、たくさんの文字列変数を設定して、何もしません。 –

+0

今のところ、単語テンプレートはちょうど 'B_twitter_date'というタイトルのブックマークに1つの単語がくるように設定されています - クイック実行と同じように。 ** Sub PopulateColumnLocations()**ヘッダー名を取得します。 ** Sub DictionaryData()**ワークシート「ヘッダー」の下のデータと、ブックマークのマッピングを含むワークシートを格納します。 ** Sub Worddoc()** 文字列のデータをブックマークにプッシュしてから繰り返しますか? これがあまりにも明らかでない場合は、ヘルプファイルのサンプルを送信できます。 ありがとうTim –

答えて

関連する問題