Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    May 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Copy Bookmarks word 2010 and paste special excel 2010

    Hi,
    I,m programmer, but never had used VB before, I need to copy some bookmarks from word 2010 and prepare to update into mysql or excel. Now i have a macro to copy and paste correctly from word and create an excel, but i need put all the content as columns for my database...
    Code:
    Sub ExportBookmarksToExcel()
    '
    ' ExportBookmarksToExcel Macro
    '
    '
    Dim bk As Bookmark
    Dim appXl As Excel.Application
    Dim wbk As Excel.Workbook
    Dim wst As Excel.Worksheet
    Dim lRow As Long
    
    Set appXl = CreateObject("Excel.Application")
    With appXl
      .Visible = True
      Set wbk = .Workbooks.Add
      Set wst = wbk.Worksheets(1)
      lRow = 0
    End With
    
    For Each bk In ActiveDocument.Bookmarks
      lRow = lRow + 1
      wst.Cells(lRow, 1) = bk.Name
      wst.Cells(lRow, 2) = bk.Range.Text
    Next bk
    wst.UsedRange.Columns.AutoFit
    End Sub
    Last edited by macropod; 2013-05-27 at 19:29. Reason: Added code tags & formatting

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,864
    Thanks
    0
    Thanked 179 Times in 165 Posts
    Try:
    Code:
    Sub ExportBookmarksToExcel()
    '
    ' ExportBookmarksToExcel Macro
    '
    '
    Dim i As Long
    Dim appXl As Excel.Application
    Dim wbk As Excel.Workbook
    Dim wst As Excel.Worksheet
    
    Set appXl = CreateObject("Excel.Application")
    With appXl
      .Visible = True
      Set wbk = .Workbooks.Add
      Set wst = wbk.Worksheets(1)
      lRow = 0
    End With
    
    With ActiveDocument
      For i = 1 To .Bookmarks.Count
        With .Bookmarks(i)
          wst.Cells(1, i) = .Name
          wst.Cells(2, i) = .Text
        End With
      Next
    End With
    wst.UsedRange.Columns.AutoFit
    End Sub
    PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  4. #3
    New Lounger
    Join Date
    May 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Copy Bookmarks word 2010 and paste special excel 2010

    Now is working, just need to add .Range.Text inside line: "wst.Cells(2, i) = .Text".... Thanks so much!!!

    Sub ExportBookmarksToExcel()
    '
    ' ExportBookmarksToExcel Macro
    '
    '
    Dim i As Long
    Dim appXl As Excel.Application
    Dim wbk As Excel.Workbook
    Dim wst As Excel.Worksheet

    Set appXl = CreateObject("Excel.Application")
    With appXl
    .Visible = True
    Set wbk = .Workbooks.Add
    Set wst = wbk.Worksheets(1)
    lRow = 0
    End With

    With ActiveDocument
    For i = 1 To .Bookmarks.Count
    With .Bookmarks(i)
    wst.Cells(1, i) = .Name
    wst.Cells(2, i) = .Range.Text
    End With
    Next
    End With
    wst.UsedRange.Columns.AutoFit
    End Sub

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •