Opening a Workbook

  • Thread starter Thread starter Todd Huttenstine
  • Start date Start date
T

Todd Huttenstine

Below is the macro I am using that I have assigned to a
button that is located on a menu in Excel. I have this
macro saved in Personal.Xls.

I would like to add the code to it to check to see if
Workbook Stats Manager.xls is open, and if it is not open,
to open it from P:\Stats Manager.xls. After the workbook
is open it needs to run the following code.

Worksheets(1).Range("C5").Select
ActiveSheet.Paste
MsgBox "Data Pasted!", vbOKOnly
 
I haven't tested the following, but it should (mostly) work:

Dim wb As Workbook
On Error Resume Next
Set wb = Workbooks("Stats Manager.xls")
On Error GoTo 0
If wb Is Nothing Then set wb = Workbooks.Open ("P:\Stats Manager.xls")
wb.Worksheets(1).Range("C5").Select
ActiveSheet.Paste
MsgBox "Data Pasted!", vbOKOnly

Keep in mind that if the data to be pasted was copied from Excel, most
likely your macro will clear the clipboard and leave you with nothing to
paste.
 
Why would it clear the clipboard?

-----Original Message-----
I haven't tested the following, but it should (mostly) work:

Dim wb As Workbook
On Error Resume Next
Set wb = Workbooks("Stats Manager.xls")
On Error GoTo 0
If wb Is Nothing Then set wb = Workbooks.Open ("P:\Stats Manager.xls")
wb.Worksheets(1).Range("C5").Select
ActiveSheet.Paste
MsgBox "Data Pasted!", vbOKOnly

Keep in mind that if the data to be pasted was copied from Excel, most
likely your macro will clear the clipboard and leave you with nothing to
paste.

--

Vasant





.
 
Because Excel's copy and paste is quirky and needs very little encouragement
to clear the clipboard <g>. I think you just need to try it out and make
sure that there is something to paste.
 
Oh I tried and it works perfectly.

-----Original Message-----
Because Excel's copy and paste is quirky and needs very little encouragement
to clear the clipboard <g>. I think you just need to try it out and make
sure that there is something to paste.

--

Vasant




.
 
Back
Top