Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-25-2017, 07:30 AM
mihnea96 mihnea96 is offline Importing .frm and .bas files using code Windows 7 32bit Importing .frm and .bas files using code Office 2010 32bit
Novice
Importing .frm and .bas files using code
 
Join Date: Apr 2017
Posts: 26
mihnea96 is on a distinguished road
Default Importing .frm and .bas files using code

Hi,



i'm trying to make a word document that when opened installs (imports) the macros into the computer, but i've been trying to use the code bellow and kept getting the error "Method 'Import' of object'_VBComponents failed". could you help me out, please?
i've wanted to do this from Excel as i have other installs there as well and it would've been easier to do it from only one file, but it doesn't work.

code:
ActiveDocument.VBProject.VBComponents.Import Environ("SystemDrive") & Environ("HomePath") &...........


thanks in advance!
Reply With Quote
  #2  
Old 07-25-2017, 07:56 AM
gmaxey gmaxey is offline Importing .frm and .bas files using code Windows 7 32bit Importing .frm and .bas files using code Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,422
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Must be your path statement

This works for a module in the active documents parent folder:
Code:
Sub Document_New()
 ActiveDocument.VBProject.VBComponents.Import ThisDocument.Path & "\Module1.bas"
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 07-25-2017, 08:07 AM
mihnea96 mihnea96 is offline Importing .frm and .bas files using code Windows 7 32bit Importing .frm and .bas files using code Office 2010 32bit
Novice
Importing .frm and .bas files using code
 
Join Date: Apr 2017
Posts: 26
mihnea96 is on a distinguished road
Talking

the parent file (word or excel doc) will be stored in different locations on different computers while the .frm and .bas files will be downloaded (using the code from the excel doc) in a specific location on every computer. i've entered the code for finding the path of the .frm and .bas files but i don't think that's the problem. thanks!
Reply With Quote
  #4  
Old 07-25-2017, 08:15 AM
gmaxey gmaxey is offline Importing .frm and .bas files using code Windows 7 32bit Importing .frm and .bas files using code Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,422
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Does the user application Trust Center settings have "Trust access to VBA project object model" checked?
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 07-25-2017, 03:17 PM
macropod's Avatar
macropod macropod is offline Importing .frm and .bas files using code Windows 7 64bit Importing .frm and .bas files using code Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

You cannot access the VBA environment programmatically (e.g. import VBA modules, forms, etc.) unless you give trusted access to the VBA project object model. Every user who is supposed to use the procedure would have to enable that access manually, as it cannot be granted programmatically. Giving trusted access to the VBA project object model on even one PC renders every PC on the network susceptible to macro viruses and is not to be recommended except for the very brief period such access is actually required.

I suggest you rethink whatever it is you're trying to achieve.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 07-26-2017, 02:11 AM
mihnea96 mihnea96 is offline Importing .frm and .bas files using code Windows 7 32bit Importing .frm and .bas files using code Office 2010 32bit
Novice
Importing .frm and .bas files using code
 
Join Date: Apr 2017
Posts: 26
mihnea96 is on a distinguished road
Default

there was a problem with my .frm and .bas files. it works now. thank you!
Reply With Quote
Reply

Tags
auto install, install from excel, word macros

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing Pub files into another Pub document drlynda Publisher 0 11-20-2014 02:02 PM
Importing .frm and .bas files using code Importing .msg files into another PC ? bill123 Office 2 08-15-2011 09:47 AM
Is there any way of importing Indicators field through code? Prabhakar Project 0 04-07-2011 05:50 AM
Importing many vcf files in excel shiflerg Excel 0 01-26-2011 09:16 AM
Importing CSV files into Oulook victoria61485 Outlook 5 12-03-2010 05:33 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:13 AM.


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