Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 05-07-2017, 06:32 PM
jhancock1994 jhancock1994 is offline Excel to Word data import based on UserForm entry Windows 7 64bit Excel to Word data import based on UserForm entry Office 2013
Novice
Excel to Word data import based on UserForm entry
 
Join Date: May 2017
Posts: 7
jhancock1994 is on a distinguished road
Default Excel to Word data import based on UserForm entry

Hi all,

I am quite new to VBA, and am struggling somewhat with this. Essentially I require a macro that can pull data from Excel and paste into a bookmark in Word. I need it to search Excel for a word which has been inputted by the user into a fillable form, and if there is a match copy the value of another cell (e.g. 5 columns across) and paste into the bookmark. I have come up with the below code, which needs some fixing. Any help would be very greatly appreciated.

Cheers,
James

Code:
Sub CallEx3()

    Dim objExcel As New Excel.Application
    Dim exWb As Excel.Workbook
    Dim oRng As Excel.Range
    Dim oSheet As Excel.Worksheet
    Dim LastRow As Long
    
    Set exWb = objExcel.Workbooks.Open("U:\VBA Word Automation\Excel Test Sheet.xlsx")
    
    For Each oSheet In objExcel.ActiveWorkbook.Worksheets
            LastRow = Cells(Rows.Count, 1).End(xlUp).Row
             For i = 2 To LastRow
                 ThisValue = Cells(i, 1).Value
                           If ThisValue = TextBox1.Text Then
                          Cells(i, 6).Copy
                               WordApp.Selection.PasteSpecial.FillBM Link:=False,    DataType:=wdPasteText, _
                             Placement:="bmDT", DisplayAsIcon:=False                  
                 End If
            Next i

    Next oSheet


    exWb.Close

    Set exWb = Nothing
    Set objExcel = Nothing
    Set oRng = Nothing
    
    Exit Sub
   
End Sub

Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Import from multiple word files into an Excel tale asmanokhchi Word 1 04-21-2015 06:24 AM
need VBA to Transpose the Data from excel to word based on given criteria(status) winmaxservices2 Excel Programming 1 12-19-2014 10:21 PM
Excel to Word data import based on UserForm entry Import data from Excel into Word sb003848 Word 1 11-04-2014 06:30 PM
Import excel data in to SQL Server DavidBrown Excel 0 08-08-2011 04:49 AM
Import Pics and Excel Data into PP? jawillyams PowerPoint 0 03-13-2011 01:03 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:10 AM.


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