Solved

Open Save and Close Excel File on SharePoint Using a Macro

Posted on 2010-08-12
7
1,875 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

743 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

14 Experts available now in Live!

Get 1:1 Help Now