Using file path as a string in range().formula

Ludzik1993

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

I have a problem with calling a specific range from a workbook in its specific sheet by having them in the strings and then referring to them in the different workbook by creating a formula in range. (Maybe there is another easier way??)

I need to make it like this because macro is going to be used in files with different names that i can't predict, and i have to copy different ranges from them to other workbook.


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("Hidden Path :) ")

'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

Can anyone help?
Thanks!
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

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