Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #8  
Old 07-20-2016, 10:41 PM
gmayor's Avatar
gmayor gmayor is offline Dynamically select a TextBox based on range value Windows 10 Dynamically select a TextBox based on range value Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Sorry - my fault. I usually call the Excel object xlAPP and not objExcel. The code has both references The following works.
Code:
Private Sub CommandButton1_Click()

Dim objExcel As Object
Dim exWb As Object
Dim rng As Object
Dim c As Object
Dim TaskStatus As String
Dim oTB As Word.InlineShape


    Set objExcel = CreateObject("Excel.Application")
    Set exWb = objExcel.Workbooks.Open("C:\Temp\File.xlsm")
    Set rng = exWb.Sheets("STATUS_DATA").Range("WordID")

    For Each c In rng.Cells
        TaskStatus = c.Offset(0, 1)
        For Each oTB In ActiveDocument.InlineShapes
            If oTB.OLEFormat.Object.Name = c Then
                oTB.OLEFormat.Object.Text = TaskStatus
                Exit For
            End If
        Next oTB
    Next

    exWb.Close
    objExcel.Quit

    'Label1.Caption = "Job task status last updated: " & Date
    Set exWb = Nothing
    Set objExcel = Nothing
    Set rng = Nothing
    Set c = Nothing
    Set oTB = Nothing
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
 

Tags
textbox, word vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro/VBA code to select ALL text in a textbox in microsoft excel and add a new row jyfuller Excel Programming 11 06-01-2015 08:49 PM
Dynamically select a TextBox based on range value select a cluster of point from a range based on x and y values sandcharles Excel 5 02-19-2015 06:15 AM
Dynamically select a TextBox based on range value Generating Print Labels Dynamically Based on SQL Server expinch Word 1 11-26-2014 10:05 PM
Dynamically select a TextBox based on range value Dynamically changing drop-down list based on selection? (Word Form) laurarem Word 1 02-21-2013 10:17 PM
Dynamically select a TextBox based on range value Display result in textbox based on the input of another textbox scarymovie Word VBA 5 05-16-2012 07:05 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:32 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