473,513 Members | 2,339 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Embedded Excel in Word VBA

94 New Member
OK, I realise this isn't directly an Access question (although the spreadsheet I want to link to is created by access), but here goes:

I have created a pecie of software in Access that creates a standardised set of folders for projects, which contain a mixture of excel and word documents. It also creates a spreadsheet in one of the files which contains all the project information (locked, so you can only update it by using access to create a new one, and archives the old one with a revision number).

I have managed to create an Excel Macro which automatically updates all the links in an excel file to look at the correct details, which is as follows:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Sub Update()
  3. On Error GoTo Update_error
  4. Dim errorstate As Integer
  5. errorstate = 1
  6.  
  7. Dim s As String
  8. Dim splitdone As Variant
  9.  
  10. s = ActiveWorkbook.Path
  11.  
  12. splitdone = Split(s, "\")
  13.  
  14. Dim newpath As String
  15. Dim newpath2 As String
  16.  
  17. newpath = "\\" & splitdone(2) & "\" & splitdone(3) & "\" & splitdone(4) & "\" & splitdone(5) & "\" & splitdone(6) & "\a. Site Details\SiteDetails.xlsx"
  18. 'MsgBox newpath, vbInformation, "path"
  19.  
  20.  
  21. Dim currentlinks As Variant
  22. currentlinks = ActiveWorkbook.LinkSources(xlExcelLinks)
  23. If Not IsEmpty(currentlinks) Then
  24. Dim i As Integer
  25.  
  26. For i = 1 To UBound(currentlinks)
  27.  
  28. ActiveWorkbook.ChangeLink Name:= _
  29.         currentlinks(i), NewName:= _
  30.         newpath, Type:=xlExcelLinks
  31. Next i
  32.  
  33. Else
  34. MsgBox "No Links Found", vbCritical, "SCM"
  35. End If
  36. Exit Sub
  37.  
  38.  
  39. Line1:
  40. errorstate = errorstate + 1
  41. Dim currentlinks1 As Variant
  42. currentlinks1 = ActiveWorkbook.LinkSources(xlExcelLinks)
  43. If Not IsEmpty(currentlinks1) Then
  44. newpath2 = splitdone(0) & "\" & splitdone(1) & "\" & splitdone(2) & "\" & splitdone(3) & "\a. Site Details\SiteDetails.xlsx"
  45. 'MsgBox newpath2, vbInformation, "path 2"
  46. Dim i1 As Integer
  47.  
  48. For i1 = 1 To UBound(currentlinks1)
  49.  
  50. ActiveWorkbook.ChangeLink Name:= _
  51.         currentlinks1(i1), NewName:= _
  52.         newpath2, Type:=xlExcelLinks
  53. Next i1
  54.  
  55. Else
  56. MsgBox "No Links Found", vbCritical, "SCM"
  57. End If
  58.  
  59.  
  60. Exit Sub
  61.  
  62. Update_error:
  63. Select Case errorstate
  64. Case Is = 1
  65. GoTo Line1
  66. Case Else
  67. MsgBox "Unable To Update Links", vbCritical, "SCM"
  68. End Select
  69.  
  70. End Sub
  71.  
Which works perfectly. However, obviously it only works in excel, not word. I have tried embedding Excel worksheets in word and using the same links as I would use in the excel spreadsheets, which appears to work fine, however, I can't get them to update using the above code. It appears that the problem is the ActiveWorkbook.Changelinks part, it doesn't pick up the excel workbook embedded in the document and therefore won't change it.

Any idea if:
a) there is a way to make the code see the embedded worksheets

Or

b) there is a better way of having text that updates itself in Word.

I have a feeling B is the better option... ;)

Thanks!
Jun 23 '11 #1
1 3147
NeoPa
32,557 Recognized Expert Moderator MVP
Check out Application Automation. I suspect this will help you resolve all your difficulties (but let us know if you need further help). Pay particular attention to post #2 with regards to developing code for a foreign environment (Word from Excel or Excel from Access etc).
Jun 23 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2570
by: Bob N5 | last post by:
I am working on an application that uses interop to do some simple operations with both Excel and Word. I have most of functionality working, but ran into issues on making things work with both...
0
2901
by: ghanley | last post by:
I have searched the web all day for a lead on this. I have found how to control the Graph object mut not the embedded excel unbound object frame. I am trying to chart the data below on one...
6
5661
by: ghanley | last post by:
Does anyone know how to change the datasource of an Embedded Excel chart in an unbound Object Frame. How to reference the properties?? I want to do something like this. Dim XLChart as...
0
1788
by: Pranav | last post by:
I've a web page that displays report data in a data grid an a chart ( I'm using Chart Fx for .Net which creates .PNG files on Server) I've a requirement to export the datagrid and chart both to...
0
1081
by: et | last post by:
I am trying to follow http://msdn2.microsoft.com/en-us/library/aa701256(office.11).aspx#Office2003Integratingwithaspnet20_CreatingtheWord2003DocumentTemplate which appears to be absolutely useless...
0
1623
by: Pradnya Patil | last post by:
Hi , I need to export some of the reports to MS EXCEL & MS WORD in a WEB APPLICATION.I also need to LOCK some of the Columns in EXCEL-sheet.Right now I need to run the Interoperability...
3
1682
by: Tequilaman | last post by:
Here comes are real tricky one: I'm approaching a project that seems impossible at first sight. I want to merge an Excel list where I find who will get which kind of information by email, with a...
0
1292
by: buddhatpm | last post by:
Hi, I'm trying to allow the user of a power point slide to change the value of cells in an embedded excel worksheet while in presentation mode (and therefore allow automatic calculation of a...
2
1744
overcomer
by: overcomer | last post by:
Hi, My problem is i dont know the syntax for opening/writing data/closing excel/word file via vba ms access.. If you know links or sites that could be helpful... thanks so much...
5
11545
Oralloy
by: Oralloy | last post by:
Folks, I have a need to access JIRA REST services from VBA under Excel, Word, and possibly Access. Unfortunately I'm stuck with JSON. I've got XML figured out; but I can't find any good packages...
0
7267
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7175
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7391
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7553
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5697
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4754
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3247
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
466
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.