Solved

Open Save and Close Excel File on SharePoint Using a Macro

Posted on 2010-08-12
7
1,918 Views
Last Modified: 2012-05-10
Hi,
I'm trying to open in edit mode, save, and then close an Excel File on SharePoint Using a Macro within another Excel file.

Here is the code I have been able to piece together so far.  It only opens the workbook on the sharepoint, but it opens in read only mode, and it does not save and close.  

Can someone help me fill in what I'm missing?

Sub OpenSaveCloseSharepoint()

Dim xlApp As Excel.Application
Dim wb As Workbook
Dim xlFile 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.
Workbooks.Open xlFile

Set xlApp = New Excel.Application
xlApp.Visible = True

Set wb = xlApp.Workbooks.Open(xlFile, , False)

ActiveWorkbook.Close True

MsgBox wb.Name & " Workbook saved"

End Sub

Open in new window

0
Comment
Question by:prodempsey
  • 4
  • 3
7 Comments
 
LVL 13

Expert Comment

by:MWGainesJR
ID: 33421332

Sub OpenSaveCloseSharepoint() 

 

Dim wb As Workbook 

Dim xlFile 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 

 

wb.Close True 

 

MsgBox wb.Name & " Workbook saved" 

 

End Sub

Open in new window

0
 
LVL 13

Expert Comment

by:MWGainesJR
ID: 33421345
more edits

Sub OpenSaveCloseSharepoint()   

   

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
 
LVL 6

Author Comment

by:prodempsey
ID: 33421735
Thank you for the quick reply.  There is a syntax error with this line:

set wb = Workbooks.Open xlFile
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 13

Expert Comment

by:MWGainesJR
ID: 33422363
change:
set wb = Workbooks.Open xlFile
to:
set wb = Workbooks.Open (xlFile)
0
 
LVL 6

Author Comment

by:prodempsey
ID: 33423080
This only opens and closes the excel file.  How do I get it to open in edit mode, save the excel file to the same location on the sharepoint, and then close the excel file?
0
 
LVL 13

Accepted Solution

by:
MWGainesJR earned 500 total points
ID: 33423282
That's exactly what it is doing
 

Sub OpenSaveCloseSharepoint()     

     

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   'opens the workbook  

wbname = wb.name    

wb.Close True  'closes the workbook and saves changes.....The true is telling it to savechanges.....   

     

MsgBox wbName & " Workbook saved"     

     

End Sub

Open in new window

0
 
LVL 6

Author Closing Comment

by:prodempsey
ID: 33423859
You are absolutely right, it worked just like you said it would.   I thought it was just opening and closing and not saving, but there was nothing new to save.  I added this just to test it and it worked.

ActiveCell.FormulaR1C1 = "x"
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
highlight duplicate entry 16 31
Excel 2010 - Comparison of texts in a cell 14 40
Excel - SQL export question 3 25
tricky if formula 2 0
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

864 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

19 Experts available now in Live!

Get 1:1 Help Now