Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-03-2018, 04:16 PM
jarnold231 jarnold231 is offline Opening Excel from Word Windows 10 Opening Excel from Word Office 2016
Novice
Opening Excel from Word
 
Join Date: May 2018
Posts: 2
jarnold231 is on a distinguished road
Default Opening Excel from Word

Good evening. I'm hoping someone here can give me some help with what I assume is a relatively simple VBA programming challenge, but which is well beyond my VBA capabilities.



I am trying to create a macro that performs the following actions.
  1. User opens .docm Word file
  2. VBA automatically opens a referenced
  3. Excel File The Excel file runs a Private_sub (this is all working)
  4. User answers a Application.Input box in the Excel Word document updates all links from Excel File
  5. Word requires the user to SaveAs the Word document

I understand that the VBA needs to be embedded in the Microsoft Word Objects "ThisDocument" section of VBA. I've tried a number of scripts that I've found online which include the use of Objects (things like Dim excelApp As Excel.Application), but I always get a runtime error.

Really hoping someone can give me a bit of an idiots guide to getting the basic structure of this set up.

Any help greatly appreciated.

Jake
Reply With Quote
  #2  
Old 05-03-2018, 04:59 PM
macropod's Avatar
macropod macropod is offline Opening Excel from Word Windows 7 64bit Opening Excel from Word Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

Code like:
Dim excelApp As Excel.Application
indicates the use of early binding. Did you set a reference to Excel in the VBE, via Tools|References?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-03-2018, 05:15 PM
jarnold231 jarnold231 is offline Opening Excel from Word Windows 10 Opening Excel from Word Office 2016
Novice
Opening Excel from Word
 
Join Date: May 2018
Posts: 2
jarnold231 is on a distinguished road
Default

I've added MS Excel Objects and it now works and opens the file, but only if specifically run rather than automatically. My code is currently as follows:

Code:
    

PrivateSub runOnOpen

    Call openExcel
    Call UpdateAllFields


End Sub

Sub openExcel()

  Dim excelApp As Excel.Application
  Dim openExcel As Workbook
  Dim var1 As Integer

  Set excelApp = New Excel.Application
  Set openExcel = excelApp.Workbooks.Open("filename")
  excelApp.Visible = True

End Sub

Sub UpdateAllFields()

    Application.DisplayAlerts = False
    ActiveDocument.Fields.Update
    Application.DisplayAlerts = True

End Sub
Reply With Quote
  #4  
Old 05-05-2018, 02:21 AM
macropod's Avatar
macropod macropod is offline Opening Excel from Word Windows 7 64bit Opening Excel from Word Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

Cross-posted at: https://stackoverflow.com/questions/...file-from-word
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 05-05-2018, 02:24 AM
macropod's Avatar
macropod macropod is offline Opening Excel from Word Windows 7 64bit Opening Excel from Word Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

Quote:
Originally Posted by jarnold231 View Post
I've added MS Excel Objects and it now works and opens the file, but only if specifically run rather than automatically.
You should look at the topic of auto macros for Word; Your 'runOnOpen' macro is named incorrectly for that.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
vba word



Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening Excel from Word Opening word document from excel 2013 Aurelius Excel Programming 1 03-12-2017 01:47 PM
Opening Excel from Word Opening excel from word AXbean Word VBA 2 02-26-2017 12:59 AM
Opening Excel from Word Hyperlinks error msg on opening in Excel, Word matilda Excel 3 05-04-2015 07:06 AM
Opening Excel from Word Word Document Not Opening With Excel VBA JennEx Word VBA 3 06-20-2013 10:10 AM
Slow Opening Word and Excel files itoa Office 1 05-11-2009 02:01 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:51 PM.


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