Solved

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

Posted on 2010-08-12
3
1,091 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

617 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