Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Open Save and Close Excel File on SharePoint Using a Macro

Posted on 2010-08-12
7
Medium Priority
?
2,441 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

688 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