Solved

Open Save and Close Excel File on SharePoint Using a Macro

Posted on 2010-08-12
7
2,132 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
[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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: 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.

Question has a verified solution.

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

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

752 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