Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-15-2011, 03:48 PM
macropod's Avatar
macropod macropod is online now Stop multiple pastes at bookmark Windows 7 64bit Stop multiple pastes at bookmark Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,385
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi chipnputt,

OK, if you want to preserve the source formatting, copy/paste will be needed. In that case, try:


Code:
Sub ExportToWord()
'Turn some stuff off while the macro is running
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.DisplayAlerts = False
Dim DaySheet As String, BmDateName As String, BmTimeName As String
Dim BmCourseName As String, BmTeamName As String, Courses As String
Dim BmDate As String, BmTime As String
Dim BmCourse As String, FNine As String, BNine As String
On Error Resume Next
Dim wdApp As Word.Application
Dim WdDoc As Word.Document
Set wdApp = CreateObject("Word.Application")
wdApp.Visible = True
Set WdDoc = wdApp.Documents.Open("C:\Users\Sal\Desktop\coxgroup.html")
On Error GoTo 0
For i = 2 To 7
  Select Case i
    Case i = 2: DaySheet = "Monday"
    Case i = 3: DaySheet = "Tuesday"
    Case i = 4: DaySheet = "Wednesday"
    Case i = 5: DaySheet = "Thursday"
    Case i = 6: DaySheet = "Friday"
    Case i = 7: DaySheet = "Saturday"
  End Select
  ' define bookmark names
  BmDateName = DaySheet & "Date"
  BmCourseName = DaySheet & "Course"
  BmTimeName = DaySheet & "Time"
  BmTeamName = DaySheet & "Teams"
  Courses = Worksheets(DaySheet).Range("D24")
  FNine = Proper(CutFirstWord(Courses))
  BNine = Proper(CutLastWord(Courses))
  ' define bookmark text
  BmCourse = FNine & " - " & BNine
  BmDate = " " & ThisWorkbook.Worksheets("Sign-Ups").Cells(1, i)
  BmDate = Format(BmDate, "dddd - mmmm d, yyyy")
  If Worksheets(DaySheet).Cells(24, 1) = "Y" Then
    BmTime = Format(Worksheets("Sign-Ups").Cells(3, i), "h:m AM/PM") & " SHOTGUN"
  Else
    BmTime = "TEE TIMES"
  End If
  ' send text data to word doc
  Call WB(BmDateName, BmDate)
  Call WB(BmCourseName, BmCourse)
  Call WB(BmTimeName, BmTime)
  Worksheets(DaySheet).Range(BmTeamName).Copy
  ' paste team data into word doc
  With WdDoc
    'Identify current Bookmark range and insert text
    If .Bookmarks.Exists(BmTeamName) Then
      Set BmkRng = .Bookmarks(BmTeamName).Range
      BmkRng.PasteSpecial Link:=False, DataType:=wdPasteHTML, _
      Placement:=wdInLine, DisplayAsIcon:=False
      BmkRng.End = BmkRng.End + Len(Worksheets(DaySheet).Range(BmTeamName).Value)
      .Bookmarks.Add BmTeamName, BmkRng
    Else
      MsgBox "Bookmark: " & BmTeamName & " not found."
    End If
  End With
  Application.CutCopyMode = False
Next i
WdDoc.Close SaveChanges:=True, OriginalFormat:=1
wdApp.Quit
Set WdDoc = Nothing: Set wdApp = Nothing
'Turn everything back on
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.DisplayAlerts = True
Application.StatusBar = False
End Sub
Note: I've cleaned up the code somewhat, deleting numerous unused/redundant variables and making use of one that was declared but not used.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #2  
Old 07-16-2011, 05:43 PM
chipnputt chipnputt is offline Stop multiple pastes at bookmark Windows Vista Stop multiple pastes at bookmark Office 2007
Novice
Stop multiple pastes at bookmark
 
Join Date: Jul 2011
Posts: 5
chipnputt is on a distinguished road
Smile

Hi macropod

I appreciate the clean up and redundancies that you took time out of your schedule to show me. I have done the same to my code and executed it. Thank you for your time, effort and patience. Problem solved!!!

Sal
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Stop multiple pastes at bookmark VBA to insert Bookmark rockwellsba Word VBA 2 05-31-2011 01:07 AM
Help with PPT AddIn that pastes slides into another presentation matt.wilson PowerPoint 0 01-05-2011 03:28 PM
Controlling Style when a user pastes into a form Cris0205 Word 0 08-05-2010 04:33 PM
Stop multiple pastes at bookmark Can you stop multiple calendars from fading? JohnGalt Outlook 2 08-05-2010 09:06 AM
Word only pastes plain text seskanda Word 6 02-19-2010 10:01 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:02 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft