VBA - Using file path as a strin to call in range().formula

Status
Not open for further replies.

Ludzik1993

New Member
Joined
Oct 8, 2018
Messages
2
Hi everyone,

I have a problem with referring to a different workbook and it's specific sheet and range to put it to the formula in a cell. I need to refer to a path and file name by using string (maybe there is different option?) because the file name and it's paths can will change every month.

There is my Code so far:

Code:
Sub KopiowanieRaportu()

'GENEROWANIE ŚCIEŻKI AKTYWNEGO PLIKU
Dim MF_Name As String
Dim MF_Path As String

MF_Name = Application.ThisWorkbook.Name
MF_Path = Application.ThisWorkbook.Path

'POBIERANIE NUMERU INDEKSU DLA AKTYWNEGO SKOROSZYTU
Dim MF_SheetName As String
MF_SheetName = ActiveSheet.Name

Dim MF_PathToSheet As String
MF_PathToSheet = MF_Path & "\[" & MF_Name & "]" & MF_SheetName & "'!"
Sheets(PG_NazwaSkoroszytu).Range("M2") = MF_PathToSheet

'PRZYPISYWANIE NAZWY PLIKU MIESIECZNYCH TAPORTOW PER SPÓŁKA DO STAŁEJ
Dim MonthyRaport As Workbook

'OTWIERANIE RAPORTU PER SPÓŁKA
Application.DisplayAlerts = False
Set MonthyRaport = Workbooks.Open("     ")

'KOPIOWANIE MerService

Application.DisplayAlerts = False
Windows("Wykonanie budżetu GRUPA OEX2018").Activate
Sheets("MS_w").Select
Range("K4").Formula = 'HERE I WANT TO REFER TO STRINGS

Hope someone have a solution :)
Thanks!
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,933
Messages
6,175,481
Members
452,647
Latest member
MatthewBiersay

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top