Solved

Open Save and Close Excel File on SharePoint Using a Macro

Posted on 2010-08-12
7
2,026 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
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…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

828 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