简体   繁体   English

动态工作簿名称更改和单元格引用-是否可以?

[英]Dynamic Workbook Name changes and cell references - Is it possible?

my question is a pre-code question, as I would like to verify if and which is the best option to go about this - either formula, VBA or not possible. 我的问题是一个前置代码问题,因为我想验证是否和哪个是解决此问题的最佳选择-公式,VBA还是不可能。

I have a main workbook with an array of codes inside cells in sheet 1 - all in the format HXXX-XXX-XXX where X is numbers ranging from 0-9. 我有一个主工作簿,在工作表1的单元格内有一系列代码-格式均为HXXX-XXX-XXX,其中X是介于0-9之间的数字。 Each code has an associated revision number as shown in the attached picture. 每个代码都有一个关联的修订号,如附图所示。

在此处输入图片说明

The workbook itself is named in the format: 'HXXX-XXX-XXX-YY Example Title' where YY can be any number starting from 0 to infinity (in theory). 工作簿本身以以下格式命名:“ HXXX-XXX-XXX-YY示例标题”,其中YY可以是从0到无穷大的任意数字(理论上)。 Only YY is subject to updates in the title. 标题中只有YY更新。 If changes are made in this workbook, then a new version is saved, with the YY changing in the title to the next consecutive number - Nothing else changes. 如果在此工作簿中进行了更改,则将保存一个新版本,其中YY的标题中的字母更改为下一个连续的数字-其余均未更改。

From this main workbook there are a large number of other workbooks (around 50) which share the same codes and revisions. 在此主要工作簿中,还有许多其他工作簿(约50个)共享相同的代码和修订版。 My goal is to link all these workbooks up so that I only have to update a core main workbook and the rest of the codes (HXXX-XXX-XXX) revisions in all the other linked workbooks update accordingly. 我的目标是将所有这些工作簿链接起来,以便我只需要更新一个核心主工作簿,而所有其他链接的工作簿中的其余代码(HXXX-XXX-XXX)修订版也会相应地更新。

The problem is that the other linked workbooks have a dynamic name in the format: 'HXXX-XXX-XXX-YY Example Title 2' where YY can be any number starting from 0 to infinity. 问题是其他链接的工作簿具有以下格式的动态名称:'HXXX-XXX-XXX-YY示例标题2',其中YY可以是从0到无穷大的任何数字。 YY gets updated to the next consecutive number if a change is made inside the document and this document is then saved as a separate document using Save As. 如果在文档内部进行了更改,则YY更新为下一个连续编号,然后使用“另存为”将该文档另存为单独的文档。 NOTE: not all workbooks will get updated at the same time, as it all depends on which codes and therefore revisions are changing. 注意:并非所有工作簿都会在同一时间进行更新,因为这完全取决于哪些代码,因此修订版本也在变化。

My question is firstly, is this possible with current excel functions to update links with ever-changing workbook links, which are saved as different files each time in the same folder? 我的问题是,首先,当前的excel函数能否用不断变化的工作簿链接更新链接,而每次将工作簿链接保存在不同的文件中?

Secondly, I have read about the INDIRECT function, but it is limited only to having the required workbooks opened at the same time as the updates to the main workbook, hence I am unsure that Formulas will work (I will be linking 50 workbooks to the main workbook) - From this I am gauging that VBA may be the best option, but I would like to double check this is possible before I begin attempting the code. 其次,我已经阅读了INDIRECT函数,但是它仅限于在更新主工作簿的同时打开所需的工作簿,因此,我不确定公式是否会起作用(我将50个工作簿链接到主工作簿)-由此,我正在评估VBA可能是最好的选择,但是我想在开始尝试代码之前再次检查这是否可行。

Of course the use of Formulas in the sheets would be much better, but because the file names are dynamic, and since the updated workbooks are saved as different files each time changes are made to it, I don't believe this is possible. 当然,在工作表中使用“公式”会更好,但是由于文件名是动态的,并且由于每次对其进行更改时更新的工作簿都保存为不同的文件,因此我认为这是不可能的。

If I understand your problem correctly you need to differentiate between 3 things. 如果我正确理解了您的问题,则需要区分三件事。

Using only Excel Formulas. 仅使用Excel公式。 The problem with this is that formulas crossing workbooks have the big disadvantage, that you need to have the source-workbook open, otherwise manny formulas will not work correctly or update. 这样做的问题是,跨越工作簿的公式具有很大的缺点,您需要打开源工作簿,否则,很多公式将无法正常工作或更新。 You also have the disadvantage that saving the file needs still to be done automatically. 您还具有一个缺点,即仍然需要自动完成文件的保存。 The advantage is that you do not need VBA macros. 优点是您不需要VBA宏。

Using Power Query With Power Query youmight be able to solve the problems with the dynamic names.You can even read a whole folder of files, combine them and do transformations without the need to open the files manually. 使用Power Query使用Power Query可以解决动态名称的问题。您甚至可以读取文件的整个文件夹,合并它们并进行转换,而无需手动打开文件。 But you still need to save new files manually and the files will only update once they are opened. 但是您仍然需要手动保存新文件,并且这些文件仅在打开后才会更新。

Using VBA You can prettymuch do everything you asked in your problem description but VBA has its own disadvantages. 使用VBA您可以执行问题描述中要求的所有操作,但是VBA有其自身的缺点。 Firstly the file-format ".xlsm" is not allowed by the IT department everywhere. 首先,各地的IT部门都不允许使用文件格式“ .xlsm”。 Also to work, every user using the files needs to activate macros, otherwise the macros won't get executed. 为了起作用,使用文件的每个用户都需要激活宏,否则宏将不会执行。 Therefore I think a VBA solution is better fitted if you only have a small circle of users or if you can execute the macros on your own (eg if the main workbook was updated, you need to execute a macro which opens, modifies and saves all affected files). 因此,我认为如果您只有一小部分用户或者可以自行执行宏(例如,如果主工作簿已更新,则需要执行一个可打开,修改并保存所有宏的宏),VBA解决方案更适合受影响的文件)。 After that you colleagues do not need VBA themself. 之后,您的同事就不需要他们自己的VBA。

Possible solution: To avoid VBA you could try to create a Power Query in each "other workbook". 可能的解决方案:为了避免使用VBA,您可以尝试在每个“其他工作簿”中创建一个Power Query。 The query will read all filenames in the folder where the main workbook is located. 该查询将读取主工作簿所在的文件夹中的所有文件名。 Now you sort and filter for the workbook with the newest/highest ID/Titel automatically and load the result as an seperate Excel sheet (all that is possible with power query and without VBA). 现在,您可以自动对具有最新/最高ID /标题的工作簿进行排序和过滤,并将结果作为单独的Excel工作表加载(使用Power查询和不使用VBA即可完成所有工作)。 Now you can use the "indirect" formula to use the ID/Titel to link to the newest main workbook. 现在,您可以使用“间接”公式来使用ID / Titel链接到最新的主工作簿。 As mentioned above this will require that the main workbook is opened. 如上所述,这将需要打开主工作簿。 Otherwise the indirect formula will not update the values. 否则,间接公式将不会更新值。 If that is out of the question, you probably need to go with VBA. 如果这是不可能的,则可能需要使用VBA。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM