Solved

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

Posted on 2010-08-12
3
1,051 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
3 Comments
 
LVL 5

Expert Comment

by:mikeada
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now