Solved

MS Access Macro to Open, Save, and Close and existing Excel File in SharePoint

Posted on 2010-08-12
3
1,085 Views
Last Modified: 2013-11-27
How can I adapt the code below that is currently working in Excel to work in a macro module in Access 2007 to open an excel file in SharePoint in edit mode, save it, then close it.

Here is the Excel VBA that is working which MWGainesJR recently helped create:

Private Sub Workbook_Open()

Dim wb As Workbook
Dim xlFile As String
Dim wbname As String
xlFile = "http://sharepoint/sites/MYD_18434/Report%20Library/Bankruptcy/BK%20Timely%20Setup%20Removal%20Daily%20Report/Bk%20Timely%20Setups%20Removals%20Dashboard.xls"
   
'Open Excel File.
Set wb = Workbooks.Open(xlFile)

wbname = wb.Name
wb.Close True
   
MsgBox wbname & " Workbook saved"
   
End Sub
 

Open in new window

0
Comment
Question by:prodempsey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 5

Expert Comment

by:mikeada
ID: 33425044
when running from in access, do you want the file to open in excel? or are you going to do something in code and save it?
0
 
LVL 20

Accepted Solution

by:
GrahamMandeno earned 500 total points
ID: 33425077
From Access you need to create an instance of Excel and then you can use very similar code (see below)
--
Graham Mandeno [Access MVP]

Dim xlApp as Object ' <<< add
Dim wb As Object ' <<< change
Dim xlFile As String
Dim wbname As String

Set xlApp = CreateObject("Excel.Application") ' <<< add

xlFile = "http://sharepoint/sites/MYD_18434/Report%20Library/Bankruptcy/BK%20Timely%20Setup%20Removal%20Daily%20Report/Bk%20Timely%20Setups%20Removals%20Dashboard.xls"
   
'Open Excel File.
Set wb = xlApp.Workbooks.Open(xlFile) ' <<< change

wbname = wb.Name
wb.Close True

MsgBox wbname & " Workbook saved"

xlApp.Quit ' <<< add
Set wb = Nothing ' <<< add
Set xlApp = Nothing ' <<< add

Open in new window

0
 
LVL 6

Author Closing Comment

by:prodempsey
ID: 33425627
It worked!

Option Compare Database
Sub OpenSpecific_xlFile()



Dim xlApp As Object ' <<< add
Dim wb As Object ' <<< change
Dim xlFile As String
Dim wbname As String

Set xlApp = CreateObject("Excel.Application") ' <<< add

xlFile = "http://sharepoint/sites/MYD_18434/Report%20Library/Bankruptcy/BK%20Timely%20Setup%20Removal%20Daily%20Report/Bk%20Timely%20Setups%20Removals%20Dashboard.xls"
   
'Open Excel File.
Set wb = xlApp.Workbooks.Open(xlFile) ' <<< change

wbname = wb.Name
wb.Close True

MsgBox wbname & " Workbook saved"

xlApp.Quit ' <<< add
Set wb = Nothing ' <<< add
Set xlApp = Nothing ' <<< add

End Sub
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question