Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #31  
Old 08-16-2018, 01:02 AM
macropod's Avatar
macropod macropod is offline Need macro to fill the values in msword based on the excel sheet info Windows 7 64bit Need macro to fill the values in msword based on the excel sheet info Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

Try:
Code:
Sub GetExcelData()
Application.ScreenUpdating = False
'Note: A VBA Reference to the Excel Object Model is required, via Tools|References
Dim xlApp As New Excel.Application, xlWkBk As Excel.Workbook, xlWkSht As Excel.Worksheet
Dim StrWkBkNm As String, i As Long, j As Long, r As Long, x As Long
StrWkBkNm = ThisDocument.Path & "\Data to fill.xlsx"
If Dir(StrWkBkNm) = "" Then
  MsgBox "Cannot find the designated workbook: " & StrWkBkNm, vbExclamation
  Exit Sub
End If
With xlApp
  .Visible = False
  .DisplayAlerts = False
  Set xlWkBk = .Workbooks.Open(FileName:=StrWkBkNm, ReadOnly:=True, AddToMRU:=False)
End With
Set xlWkSht = xlWkBk.Worksheets("Sheet1")
With ActiveDocument
  For i = 1 To .Tables.Count
    r = i + 1: x = 0
    With .Tables(i)
      With .Range
        .Find.Execute FindText:="<PV:>", MatchWildcards:=True, Wrap:=wdFindStop
        If .Find.Found = True Then x = .Range.Cells(1).RowIndex
      End With
      If x > 0 Then
        .Cell(x, 2).Range.Text = "PV: " & xlWkSht.Range("B" & r).Value
        With .Cell(x + 1, 2).Range
          .ContentControls(1).Checked = (xlWkSht.Range("F" & r).Value = "Y")
          .ContentControls(2).Checked = (xlWkSht.Range("F" & r).Value = "Y")
          .ContentControls(3).Checked = (xlWkSht.Range("G" & r).Value = "Y")
        End With
        With .Cell(x + 1, 1).Range
          With .ContentControls(1)
            .Type = wdContentControlText
            .Range.Text = xlWkSht.Range("A" & r).Value
            .Type = wdContentControlDropdownList
          End With
          With .ContentControls(2)
            .Type = wdContentControlText
            .Range.Text = xlWkSht.Range("D" & r).Value
            .Type = wdContentControlDropdownList
          End With
          With .ContentControls(3)
            .Type = wdContentControlText
            .Range.Text = xlWkSht.Range("C" & r).Value
            .Type = wdContentControlDropdownList
          End With
        End With
      End If
    End With
  Next
End With
xlWkBk.Close False
xlApp.Quit
Set xlWkSht = Nothing: Set xlWkBk = Nothing: Set xlApp = Nothing
Application.ScreenUpdating = True
End Sub

__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #32  
Old 08-16-2018, 01:57 AM
ganesang ganesang is offline Need macro to fill the values in msword based on the excel sheet info Windows XP Need macro to fill the values in msword based on the excel sheet info Office 2016
Competent Performer
Need macro to fill the values in msword based on the excel sheet info
 
Join Date: Jul 2018
Posts: 171
ganesang is on a distinguished road
Default

Thanks Much Paul!!
Reply With Quote
  #33  
Old 08-20-2018, 06:14 AM
ganesang ganesang is offline Need macro to fill the values in msword based on the excel sheet info Windows XP Need macro to fill the values in msword based on the excel sheet info Office 2016
Competent Performer
Need macro to fill the values in msword based on the excel sheet info
 
Join Date: Jul 2018
Posts: 171
ganesang is on a distinguished road
Default

Hi Paul!!

Thanks for provide the new code.

When i try to run this code i have the error on line no 23....

Please find the screenshot and advise.
Attached Images
File Type: png error at line no 23.png (27.5 KB, 16 views)
Reply With Quote
  #34  
Old 08-20-2018, 03:09 PM
macropod's Avatar
macropod macropod is offline Need macro to fill the values in msword based on the excel sheet info Windows 7 64bit Need macro to fill the values in msword based on the excel sheet info Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

Change:
x = .Range.Cells(1).RowIndex
to:
x = .Cells(1).RowIndex
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #35  
Old 08-23-2018, 05:42 AM
ganesang ganesang is offline Need macro to fill the values in msword based on the excel sheet info Windows XP Need macro to fill the values in msword based on the excel sheet info Office 2016
Competent Performer
Need macro to fill the values in msword based on the excel sheet info
 
Join Date: Jul 2018
Posts: 171
ganesang is on a distinguished road
Default

Hi Paul

Thanks for the reply.

Still the check boxes are not checked for versions (Version1, Version2, Version3).

Please check and advise.
Reply With Quote
  #36  
Old 08-23-2018, 06:05 AM
macropod's Avatar
macropod macropod is offline Need macro to fill the values in msword based on the excel sheet info Windows 7 64bit Need macro to fill the values in msword based on the excel sheet info Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

They were in the code for the sample document you provided. If they're not being checked now, that suggests there are yet more differences than you admitted to in posts 28 & 30...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #37  
Old 08-24-2018, 12:06 AM
ganesang ganesang is offline Need macro to fill the values in msword based on the excel sheet info Windows XP Need macro to fill the values in msword based on the excel sheet info Office 2016
Competent Performer
Need macro to fill the values in msword based on the excel sheet info
 
Join Date: Jul 2018
Posts: 171
ganesang is on a distinguished road
Default

Hi Paul

Thanks for the reply.

If any para exist in the "PV" cell, how to retain that para without deleting that one?

Also, the excel data that i provided sometimes protected. So, is there any possible to detect the values from the drop down in the word based on the excel data instead of copy (ex., Esy=1-Easy etc...) from the excel (using "case" option).

Please advise.

thanks again
ganesang
Reply With Quote
  #38  
Old 08-24-2018, 12:21 AM
macropod's Avatar
macropod macropod is offline Need macro to fill the values in msword based on the excel sheet info Windows 7 64bit Need macro to fill the values in msword based on the excel sheet info Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

Yet another difference you failed to mention...

To deal with that, you might change:
.Cell(x, 2).Range.Text = "PV: " & xlWkSht.Range("B" & r).Value
to:
.Cell(x, 2).Range.InsertAfter xlWkSht.Range("B" & r).Value
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #39  
Old 08-24-2018, 02:05 AM
ganesang ganesang is offline Need macro to fill the values in msword based on the excel sheet info Windows XP Need macro to fill the values in msword based on the excel sheet info Office 2016
Competent Performer
Need macro to fill the values in msword based on the excel sheet info
 
Join Date: Jul 2018
Posts: 171
ganesang is on a distinguished road
Default

Hi Paul

Yes!. i forgot to mention that..

I am little learner in VBA. So please forgive me if i am not on the same route.

IF, Insertion text (PV if may be add with some additional text, how will change the code?

for ex., from "PV:" to insert "PV:0"
Reply With Quote
  #40  
Old 08-24-2018, 05:03 AM
macropod's Avatar
macropod macropod is offline Need macro to fill the values in msword based on the excel sheet info Windows 7 64bit Need macro to fill the values in msword based on the excel sheet info Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

The last lot of code I gave you inserts the string at the end of the cell; it has no effect on anything already there.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #41  
Old 08-27-2018, 09:36 PM
ganesang ganesang is offline Need macro to fill the values in msword based on the excel sheet info Windows XP Need macro to fill the values in msword based on the excel sheet info Office 2016
Competent Performer
Need macro to fill the values in msword based on the excel sheet info
 
Join Date: Jul 2018
Posts: 171
ganesang is on a distinguished road
Default

Hi Paul

If i have to change from "PV: RR" to "PV: 0" how code will change?
Reply With Quote
  #42  
Old 08-27-2018, 09:38 PM
macropod's Avatar
macropod macropod is offline Need macro to fill the values in msword based on the excel sheet info Windows 7 64bit Need macro to fill the values in msword based on the excel sheet info Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

I am getting tired of your seemingly never-ending revisiting this topic because of your document's inconsistencies. Instead of expecting me to modify the code, how about you doing a Find/Replace, to change "PV: RR" to "PV: "???
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #43  
Old 08-27-2018, 09:42 PM
ganesang ganesang is offline Need macro to fill the values in msword based on the excel sheet info Windows XP Need macro to fill the values in msword based on the excel sheet info Office 2016
Competent Performer
Need macro to fill the values in msword based on the excel sheet info
 
Join Date: Jul 2018
Posts: 171
ganesang is on a distinguished road
Default

Sorry for the inconvenience Paul

I don't realize that there are more inconsistencies found this document.

Anyway, now if i found "PV: RR", then needs to be insert after as "PV:[point value from excel]"

The above coding you given on post 38 only insert what we found.

Please advise.
Reply With Quote
  #44  
Old 08-27-2018, 09:43 PM
macropod's Avatar
macropod macropod is offline Need macro to fill the values in msword based on the excel sheet info Windows 7 64bit Need macro to fill the values in msword based on the excel sheet info Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

I have already suggested how you can fix that...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #45  
Old 08-27-2018, 09:46 PM
ganesang ganesang is offline Need macro to fill the values in msword based on the excel sheet info Windows XP Need macro to fill the values in msword based on the excel sheet info Office 2016
Competent Performer
Need macro to fill the values in msword based on the excel sheet info
 
Join Date: Jul 2018
Posts: 171
ganesang is on a distinguished road
Default

The above coding print like that, "PV: RR" to "PV: RR1" instead of "PV:1"
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need macro to fill data from different sheets based on selected item from drop down skorasika Excel Programming 1 03-13-2015 11:25 AM
Newbie to excel for starters, needing to transfer info from sheet2 to universe sheet. rogcar75 Excel 0 08-12-2014 07:21 AM
Color-fill a range of cells, based on text in a different sheet. Possible? unittwentyfive Excel 2 06-01-2014 06:48 AM
Need macro to fill the values in msword based on the excel sheet info link conditional info in word based on excel list stijnvanhoof Mail Merge 1 11-13-2012 01:55 PM
Need macro to fill the values in msword based on the excel sheet info Open Word w Excel & fill Word textboxes w info from Excel fields runtime error 4248 Joe Patrick Word VBA 2 01-30-2012 07:23 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:49 PM.


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