Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 01-04-2017, 02:27 AM
Guimenez Guimenez is offline Windows 10 Office 2013
Novice
 
Join Date: Jan 2017
Posts: 28
Guimenez is on a distinguished road
Default Add field based on excel data with keyboard shortcut

Hi,


is it possible to create a keyboard shortcut to add a field based on a excel columm and then choose the info i want with a dropdown?

Every day a make documents with lots of names and numbers, ex:

peter n.1234
John n.4321
Hector n.3333

If i can simplify my live using a keyboard shortcut to add the field and choose the name i want it will be amazing.

thanks
Reply With Quote
  #2  
Old 01-04-2017, 03:38 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,137
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

See, for example: http://www.msofficeforums.com/word-v...html#post46287
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 01-04-2017, 03:59 AM
Guimenez Guimenez is offline Windows 10 Office 2013
Novice
 
Join Date: Jan 2017
Posts: 28
Guimenez is on a distinguished road
Default Populate Dropdown List from Excel

Hi,
i'm trying to do the same thing as in http://www.msofficeforums.com/word-v...drop-down.html but without sucess.
i've created the excel file wiht lots of names in the first columm.
I've created the macro and paste the code on the #2 post and set the reference in the macro.
Now how can i call the macro to show me the dropdown with the list of excel file?
Thank you
Reply With Quote
  #4  
Old 01-04-2017, 04:53 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,137
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

I take it you added the macro to the Word document, not to the Excel workbook. The macro runs automatically when you open the document - no user action is required. For it to work with the macro as coded, though, your Word document must have a dropdown content control titled 'ID' - though you could use a different title (provided you use the same title in the document and in the code). Note also that the macro looks for a workbook named 'Workbook Name' (of all things) in your 'Documents' folder. You can change both the filename and folder.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #5  
Old 01-04-2017, 05:12 AM
Guimenez Guimenez is offline Windows 10 Office 2013
Novice
 
Join Date: Jan 2017
Posts: 28
Guimenez is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
I take it you added the macro to the Word document, not to the Excel workbook. The macro runs automatically when you open the document - no user action is required. For it to work with the macro as coded, though, your Word document must have a dropdown content control titled 'ID' - though you could use a different title (provided you use the same title in the document and in the code). Note also that the macro looks for a workbook named 'Workbook Name' (of all things) in your 'Documents' folder. You can change both the filename and folder.
Thanks for replying.
This is what i did:

The files are in my documents folder and i've changed the location on the macro
- created excel file (xlsx) and put in the first columm 10 names
- created doc file and went to macros, create new and past the code above, changing the StrWkBkNm to match my file.
- created a new dropdown and titled it "ID".

But nothing happens, i've close the document and open again the dropdown "ID" is empty.

Do you know what i'm doing wrong? I need it a lot.
Thanks
Reply With Quote
  #6  
Old 01-04-2017, 12:06 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,137
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Can you attach a document (including your modified copy of the macro) to a post (delete anything sensitive)? You do this via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #7  
Old 01-05-2017, 01:10 AM
Guimenez Guimenez is offline Windows 10 Office 2013
Novice
 
Join Date: Jan 2017
Posts: 28
Guimenez is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Can you attach a document (including your modified copy of the macro) to a post (delete anything sensitive)? You do this via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.
Thank you for trying to help me

I've attached my 2 files.
Is it possible to make a macro that when i press F8 it will show the dropdown to select the names?

thank you once again.
Attached Files
File Type: docx dados.docx (18.8 KB, 2 views)
File Type: xlsx dados.xlsx (9.3 KB, 3 views)
Reply With Quote
  #8  
Old 01-05-2017, 02:23 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,137
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

As the document you attached is in the docx format, it cannot contain a macro. Accordingly, it is not possible for me to see what you have done with the code.

Regardless, try the attached. I have adapted the code to your workbook, plus I've added the coded needed to output the value for the selected item to a second content control.

Simply save the document to the same folder as your dados.xlsx workbook.
Attached Files
File Type: docm dados.docm (33.0 KB, 2 views)
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #9  
Old 01-05-2017, 02:28 AM
Guimenez Guimenez is offline Windows 10 Office 2013
Novice
 
Join Date: Jan 2017
Posts: 28
Guimenez is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
As the document you attached is in the docx format, it cannot contain a macro. Accordingly, it is not possible for me to see what you have done with the code.

Regardless, try the attached. I have adapted the code to your workbook, plus I've added the coded needed to output the value for the selected item to a second content control.

Simply save the document to the same folder as your dados.xlsx workbook.
I've try your file but it's the same
It appears a box but i can choose nothing.
I've attached my macro.
Thank you
Attached Files
File Type: txt macro.txt (2.0 KB, 2 views)
Reply With Quote
  #10  
Old 01-05-2017, 02:33 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,137
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Did you try selecting anything from the dropdown after opening the document? If it's empty, that suggests you either didn't enable the macro when prompted to do so or that you have macros disabled on your Word installation.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #11  
Old 01-05-2017, 03:41 AM
Guimenez Guimenez is offline Windows 10 Office 2013
Novice
 
Join Date: Jan 2017
Posts: 28
Guimenez is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Did you try selecting anything from the dropdown after opening the document? If it's empty, that suggests you either didn't enable the macro when prompted to do so or that you have macros disabled on your Word installation.
I've macros in Word.

Here you have 2 prints with what is happening.
Thanks
Attached Images
File Type: png doc1.png (37.1 KB, 11 views)
File Type: png doc2.png (37.3 KB, 11 views)
Reply With Quote
  #12  
Old 01-05-2017, 03:50 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,137
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Well, unless you're dismissing the 'enable' option or you have an empty workbook in that folder, I cannot see how it is possible to end up with an empty list and no error messages.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #13  
Old 01-05-2017, 04:14 AM
Guimenez Guimenez is offline Windows 10 Office 2013
Novice
 
Join Date: Jan 2017
Posts: 28
Guimenez is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Well, unless you're dismissing the 'enable' option or you have an empty workbook in that folder, I cannot see how it is possible to end up with an empty list and no error messages.
Ok, i try to edit your macro and it says that the macros in this project are disable, how can i enable please?
Reply With Quote
  #14  
Old 01-05-2017, 04:44 AM
Guimenez Guimenez is offline Windows 10 Office 2013
Novice
 
Join Date: Jan 2017
Posts: 28
Guimenez is on a distinguished road
Default

Quote:
Originally Posted by Guimenez View Post
Ok, i try to edit your macro and it says that the macros in this project are disable, how can i enable please?
I've enabled it and it's working flawless, thank you

Please, is it possible to create an shortcut to put the 2 box after pressing it?

Ex:

Pressing F8, it will add the combox and the text area to match name+number

joao n.123456

Thank you
Reply With Quote
  #15  
Old 01-05-2017, 04:51 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,137
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Quote:
Originally Posted by Guimenez View Post
Please, is it possible to create an shortcut to put the 2 box after pressing it?

Ex:

Pressing F8, it will add the combox and the text area to match name+number

joao n.123456
I have no idea what you mean. For example, pressing F8 has nothing to do with making a dropdown selection. If you want to make a dropdown selection, click on the dropdown. Nothing could be simpler and you certainly don't need a shortcut - unless you're trying to avoid using the mouse - but even then a shortcut won't make the selection for you.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
Reply
Please reply to this thread with any new information or opinions.

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing keyboard layout - Changing/removing keyboard shortcut Hans L Windows 2 08-16-2015 05:33 PM
keyboard shortcut ilor OneNote 1 11-13-2014 02:48 PM
disable ctrl+space excel keyboard shortcut melvinjn Excel 2 11-27-2013 04:11 AM
Keyboard shortcut for bookmarks Jennifer Murphy Word VBA 1 01-06-2013 07:38 PM
Outlook Keyboard shortcut sostrow28 Outlook 1 12-10-2010 05:57 AM


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


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft