Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Closed Thread
 
Thread Tools Display Modes
  #1  
Old 07-24-2018, 05:19 PM
macropod's Avatar
macropod macropod is offline How to import list from Excel into drop-down list into word Windows 7 64bit How to import list from Excel into drop-down list into word Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,521
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

As coded, the macro looks for the workbook in:
StrWkBkNm = "C:\Users\" & Environ("Username") & "\Documents\"


which resolves to the user's 'Documents' folder. If their copy of the workbook isn't there, you'll get the error. Similarly, if you've changed the path to a common location for all users, but some don't at least have read access to that location, they'll get the error.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
  #2  
Old 07-25-2018, 12:59 AM
Guimenez Guimenez is offline How to import list from Excel into drop-down list into word Windows 10 How to import list from Excel into drop-down list into word Office 2013
Advanced Beginner
 
Join Date: Jan 2017
Posts: 33
Guimenez is on a distinguished road
Default

Thats not the problem, because my code search the excel file in the same folder that my word document.
If i remove the excel file i've another error(thats is the error that can't find the file).

this is my code.

Code:
Option Explicit
Dim StrData As String, i As Long

Private Sub Doc()
Dim xlApp As New Excel.Application, xlWkBk As Excel.Workbook, StrWkBkNm As String
StrWkBkNm = ThisDocument.Path & "\dados.xlsx"
If Dir(StrWkBkNm) = "" Then
  MsgBox "Cannot find the designated workbook: " & StrWkBkNm, vbExclamation
  Exit Sub
End If
With xlApp
  .Visible = False
  Set xlWkBk = .Workbooks.Open(FileName:=StrWkBkNm, ReadOnly:=True, AddToMRU:=False)
  With xlWkBk
    With .Worksheets(1)
      For i = 1 To .Cells(.Rows.Count, 1).End(xlUp).Row
        StrData = StrData & vbCr & Trim(.Range("A" & i))
        If Trim(.Range("B" & i)) <> "" Then StrData = StrData & " n.º " & Trim(.Range("B" & i))
      Next
    End With
    .Close False
  End With
  .Quit
End With
Call AddControls
Set xlWkBk = Nothing: Set xlApp = Nothing
End Sub

Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
Application.ScreenUpdating = False
Dim i As Long
With CCtrl
  If .Title = "ID" Then
    If .Range.Text <> .PlaceholderText Then .Delete
  End If
End With
Application.ScreenUpdating = True
End Sub

Sub AddControls()
Application.ScreenUpdating = False
Dim CCtrl As ContentControl
If StrData = "" Then
  Call Doc
  Exit Sub
End If
With Selection.Range
  .Collapse wdCollapseStart
  Set CCtrl = .ContentControls.Add(wdContentControlComboBox)
  With CCtrl
    .Title = "ID"
    .SetPlaceholderText Text:="pressione Alt+Seta para baixo"
    For i = 1 To UBound(Split(StrData, vbCr))
      .DropdownListEntries.Add Text:=Split(StrData, vbCr)(i)
    Next
  End With
End With
Application.ScreenUpdating = True
End Sub
Closed Thread

Tags
lesson plan template, teacher help



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to import list from Excel into drop-down list into word Dynamically changing drop-down list based on selection? (Word Form) laurarem Word 1 02-21-2013 10:17 PM
How to import list from Excel into drop-down list into word How to import a list of names into PowerPoint from Excel? CarpetRemnant PowerPoint 4 12-07-2012 11:08 AM
Drop down list, Can it be done??? garethreid Outlook 0 08-09-2012 06:08 AM
How to import list from Excel into drop-down list into word drop down list from external data source Excel 2007? Intruder Excel 1 08-03-2012 05:41 AM
Long List for drop down box DLo99 Word 0 02-28-2010 08:07 AM

Other Forums: Access Forums

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