Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 70
Default Open file with macros

Hello all-

I have a macro that opens a file on my network when I click on button. I
want this macro to open a file that is in cell(14,1) no matter what the
file's name is changed to. I've attached my current macro below. If I
change the actually file name in VBA code, then it works fine. But i want
to be able to change the file name in the Excel worksheet instead.

Private Sub CmdWireSheet_Click()

Dim objExcel As Object
Dim SchedWkbk As Workbook

On Error Resume Next
Set SchedWkbk = Nothing

Set objExcel = CreateObject("Excel.Application")

Set SchedWkbk = objExcel.Application.Workbooks.Open _
("O:\SEM\Common\Accounting\& .cells(14,1).value")
objExcel.Visible = True
On Error Resume Next

If SchedWkbk Is Nothing Then
MsgBox prompt:="Cannot find file. Please open file manually", _
Buttons:=vbOKOnly + vbQuestion

End If

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Open file with macros

Considering using a hyperlink rather than a button. The hyperlink will open
the file if not already openned and branch if already openned:

=HYPERLINK("file:///O:\SEM\Common\Accounting\" & A14,"file on server")

--
Gary''s Student - gsnu200759


"David T" wrote:

Hello all-

I have a macro that opens a file on my network when I click on button. I
want this macro to open a file that is in cell(14,1) no matter what the
file's name is changed to. I've attached my current macro below. If I
change the actually file name in VBA code, then it works fine. But i want
to be able to change the file name in the Excel worksheet instead.

Private Sub CmdWireSheet_Click()

Dim objExcel As Object
Dim SchedWkbk As Workbook

On Error Resume Next
Set SchedWkbk = Nothing

Set objExcel = CreateObject("Excel.Application")

Set SchedWkbk = objExcel.Application.Workbooks.Open _
("O:\SEM\Common\Accounting\& .cells(14,1).value")
objExcel.Visible = True
On Error Resume Next

If SchedWkbk Is Nothing Then
MsgBox prompt:="Cannot find file. Please open file manually", _
Buttons:=vbOKOnly + vbQuestion

End If

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 70
Default Open file with macros

Gary-

I prefer not to use a hyperlink because it will open the file within the
same workbook. This macro will open the file in entirely different workbook.
Anyhow, after playing around with the code, I figured out how to fix the
code. All I had to do was move the quotations around. Thanks for your
response.

Private Sub CmdWireSheet_Click()

Dim objExcel As Object
Dim SchedWkbk As Workbook

On Error Resume Next
Set SchedWkbk = Nothing

Set objExcel = CreateObject("Excel.Application")

Set SchedWkbk = objExcel.Application.Workbooks.Open _
("O:\SEM\Common\Accounting\" & Cells(5, 9).Value)
objExcel.Visible = True
On Error Resume Next

If SchedWkbk Is Nothing Then
MsgBox prompt:="Please check cell I5 to make sure the correct file
path is entered.", _
Buttons:=vbOKOnly + vbQuestion

End If

End Sub

"Gary''s Student" wrote:

Considering using a hyperlink rather than a button. The hyperlink will open
the file if not already openned and branch if already openned:

=HYPERLINK("file:///O:\SEM\Common\Accounting\" & A14,"file on server")

--
Gary''s Student - gsnu200759


"David T" wrote:

Hello all-

I have a macro that opens a file on my network when I click on button. I
want this macro to open a file that is in cell(14,1) no matter what the
file's name is changed to. I've attached my current macro below. If I
change the actually file name in VBA code, then it works fine. But i want
to be able to change the file name in the Excel worksheet instead.

Private Sub CmdWireSheet_Click()

Dim objExcel As Object
Dim SchedWkbk As Workbook

On Error Resume Next
Set SchedWkbk = Nothing

Set objExcel = CreateObject("Excel.Application")

Set SchedWkbk = objExcel.Application.Workbooks.Open _
("O:\SEM\Common\Accounting\& .cells(14,1).value")
objExcel.Visible = True
On Error Resume Next

If SchedWkbk Is Nothing Then
MsgBox prompt:="Cannot find file. Please open file manually", _
Buttons:=vbOKOnly + vbQuestion

End If

End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Save or open file as YYYYMMDD in Macros, how to record it Vijay Kotian Excel Discussion (Misc queries) 1 September 4th 06 02:37 PM
How can I save or open file as YYYYMMDD in Macros Vijay Kotian Excel Discussion (Misc queries) 1 September 4th 06 08:33 AM
In Excel - Use Windows Explorer instead of File Open to open file KymY Excel Discussion (Misc queries) 1 August 5th 06 09:59 PM
How to stop file open macro prompt after deleting all macros? twor57 Excel Worksheet Functions 2 November 29th 05 05:00 PM
save excel file from a table delimited file (.txt) using macros sedamfo New Users to Excel 1 February 15th 05 04:19 AM


All times are GMT +1. The time now is 07:05 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"